?
Solved

htaccess rules for URL routing

Posted on 2012-03-28
5
Medium Priority
?
478 Views
Last Modified: 2012-03-28
Hi!

I am building a URL shortener app and am having trouble getting my .htaccess file correct.  I need to funnel all requests into route.php, except for asset files (.js, .css, .png, .jpg), and two folders (lib/ and admin/).

Whats the best way to achieve this?  Here's what I have currently ( I got this from Google - I don't really understand the htaccess syntax):

# Turn rewriting on
Options +FollowSymLinks
RewriteEngine On

# Redirect requests to route.php, excluding lib + admin folders and resource assets
RewriteCond %{REQUEST_URI} !=route.php
RewriteCond %{REQUEST_URI} !^/(admin|lib)/
RewriteCond %{REQUEST_URI} !.*\.png$ [NC]
RewriteCond %{REQUEST_URI} !.*\.jpg$ [NC]
RewriteCond %{REQUEST_URI} !.*\.css$ [NC]
RewriteCond %{REQUEST_URI} !.*\.gif$ [NC]
RewriteCond %{REQUEST_URI} !.*\.js$ [NC]
RewriteRule .* route.php

Open in new window


The folder exclusion rule for lib and admin still redirect to route.php.. any ideas why?

Also, how do I remove the .php from the URL file extension, as usually done with a typical MVC environment.

Thanks..

TheFoot
0
Comment
Question by:Barry Jones
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 200 total points
ID: 37775945
0
 
LVL 12

Author Comment

by:Barry Jones
ID: 37775966
Great article - thanks, however it doesn't help me to exclude folders from my routing.. Any ideas?
0
 
LVL 7

Accepted Solution

by:
designatedinitializer earned 1800 total points
ID: 37775976
	# Send request via route.php but only if its not a real file or folder
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ route.php/$1 [L]

Open in new window

it works for me
0
 
LVL 12

Author Closing Comment

by:Barry Jones
ID: 37776009
Excellent solution - works great, nice and simple.  Thanks!

@BuggyCoder - thanks for the links - useful infos..
0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question