Solved

htaccess rules for URL routing

Posted on 2012-03-28
5
453 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
  • 2
  • 2
5 Comments
 
LVL 20

Assisted Solution

by:BuggyCoder
BuggyCoder earned 50 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 450 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 20

Expert Comment

by:BuggyCoder
ID: 37775981
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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.

920 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now