mod_rewrite, 301 problem
Posted
by
blid
on Server Fault
See other posts from Server Fault
or by blid
Published on 2010-09-19T17:28:58Z
Indexed on
2011/02/27
15:26 UTC
Read the original article
Hit count: 216
Hi,
Currently I can access specific site in two ways:
1. http://a.com/foo/bar
2. http://a.com/index.php?url=foo/bar
What I'm trying to achive is to allow to do it only using first way, and make redirect 301 on the second to the first one. Here's the code which I made so far and put into .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
#tricky part
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?url=?(.*)\ HTTP/
RewriteRule ^index\.php$ http://a.com/$1 [R=301,L]
</IfModule>
Currently it do almost all the job, it's redirecting index.php to /, but index.php?url=foo/bar to /?url=foo/bar and I can't manage to make it right. TIA.
© Server Fault or respective owner