Forum Moderators: phranque
I have mod_rewrite working, but need to create a rule and my regex skills leave a lot to be desired.
I have:
RewriteRule ^calc/(.*) /calc/beta/index.php?id=$1
This will take any url in the form of [localhost...] and make it go to index.php?id=100, however I need this changed so that it ONLY works if the url doesn't end in ".php". So if somebody goes to [localhost...] it should pull up the file /calc/100.php, but if it is [localhost...] it needs to go to index.php?id=100.
I hope it doesn’t matter but this will be running on systems with Apache 1.x and 2.x and PHP 4.x and PHP 5.x.
--
Thanks in advance
Blaine
Simply add a condition to your rule:
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule ^calc/(.*) /calc/beta/index.php?id=$1
RewriteCond $1 !\.php$
RewriteRule ^calc/(.*) /calc/beta/index.php?id=$1
The "!" character is a NOT operator in mod_rewrite, and the backslash escapes the literal period in the ".php" filetype.
Jim