Forum Moderators: phranque
I'm trying to redirect anything after the 1st slash to my script, but with certain exclusions.
For example, I want to redirect:
[mydomain.com...]
to
[mydomain.com...]
I first tried doing:
---------------------------------------------
RewriteRule ^/(.*) /script.php?var=$
---------------------------------------------
But that was also redirecting the script.php file itself.
I then tried:
---------------------------------------------
RewriteCond %{REQUEST_URI} !^/(.*)\.php
RewriteCond %{REQUEST_URI} !^/(.*)\.css
RewriteCond %{REQUEST_URI} !^/(.*)\.gif
RewriteRule ^(.*)$ /script.php?var=$1
---------------------------------------------
Which excludes .php, .css, and .gif files, but it was also redirecting the homepage to script.php.
I have a feeling this can be easily done without RewriteCond and with a simple one-line RewriteRule, but I just can't figure out how.
Any and all help would be appreciated.
Thanks!
RewriteCond $1 !\.(gif¦css¦php)$
RewriteRule ^(.+)$ /script.php?var=$1 [L]
Make sure your script can return proper content for robots.txt, favico.ico, and sitemap.xml requests, all of which are presumed to exist by all major search engines. If not, these need to be excluded from your rule as well. Consider also .jpg and other media files, pdf files, etc.
Replace the broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters.
Jim