Question



I want to redirect the following

http://www.example.com/folder/index.php?dir=Dir1
http://www.example.com/folder/index.php?dir=Dir1/Dir2

to

http://www.example.com/folder/Dir1
http://www.example.com/folder/Dir1/Dir2

I want to "301 Redirect" it NOT "Rewrite" i.e I want the "index.php?dir=" link to 301 redirect to folder structure.

Please advice?

Was it helpful?

Solution

Do this in your DocumentRoot .htaccess.

Options +FollowSymLinks 

RewriteEngine On
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]

RewriteCond %{QUERY_STRING}  ^dir=(.*)$ [NC]
RewriteRule ^  folder/%1? [L,R=301]

RewriteRule ^folder/(.+)/? folder/index.php?dir=$1 [L,QSA]

OTHER TIPS

RewriteCond %{QUERY_STRING}  ^dir=(.*)$
RewriteRule ^folder/index\.php$  folder/%1 [L,R=302]

change to 301 once working.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top