• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 490
  • Last Modified:

htaccess rules for URL routing

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
Barry Jones
Asked:
Barry Jones
  • 2
  • 2
2 Solutions
 
BuggyCoderCommented:
0
 
Barry JonesAuthor Commented:
Great article - thanks, however it doesn't help me to exclude folders from my routing.. Any ideas?
0
 
designatedinitializerCommented:
	# 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
 
Barry JonesAuthor Commented:
Excellent solution - works great, nice and simple.  Thanks!

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

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now