|
|
Subject:
mod_rewrite -> redirecting everything to a handler except a few folders
Category: Computers > Programming Asked by: wiggum24-ga List Price: $5.00 |
Posted:
11 Aug 2005 23:56 PDT
Expires: 10 Sep 2005 23:56 PDT Question ID: 554812 |
G'day :) I'm looking for some httpd.conf entries (specifically regular expressions). I'd like to use mod_rewrite to send every request to handler.php, except for a couple of folders. (images,includes,custom) |
|
Subject:
Re: mod_rewrite -> redirecting everything to a handler except a few folders
Answered By: palitoy-ga on 12 Aug 2005 00:34 PDT |
Hello wiggum24-ga Thank-you for your question. Using mod_rewrite can be complicated and usually requires a little tweaking before you get the rules exactly how you wish them to be, these things are notorious for not getting them exactly right first time! There is an excellent manual on mod_rewrite which I usually use to try and solve these problems, this can be found here: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html In your case we need to use conditional rewrites where if the request is not one of 3 folders it is redirected. To do this we need a regular expression that checks if it IS one of the folders and then reversing this. The reversing is done with the use of an ! symbol in the code given below. In my attempt below this is what is going on: 1) The rewrite engine is switched on so that we can rewrite the URL 2) A trailing slash is added if necessary to the URL 3) Check it is not the images directory 4) Check it is not the includes directory 5) Check it is not the custom directory 6) Match the query string 7) Redirect the URL to the handler.php and attach any query string ================================================== RewriteEngine on RewriteRule ^(.*[^/])$ /$1/ [L] RewriteCond %{REQUEST_URI} !^/images/ RewriteCond %{REQUEST_URI} !^/includes/ RewriteCond %{REQUEST_URI} !^/custom/ RewriteCond %{QUERY_STRING} ^(.+)$ RewriteRule ^(.+)$ /handler.php?args=%1 [L] ================================================== Please let me know how you get on with this, if it needs any tweaking please ask for clarification and I will do my best to respond swiftly. | |
| |
| |
|
|
There are no comments at this time. |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |