301 Redirect index.php?dir= to a folder?
Вопрос
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?
Решение
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]
Другие советы
RewriteCond %{QUERY_STRING} ^dir=(.*)$
RewriteRule ^folder/index\.php$ folder/%1 [L,R=302]
change to 301 once working.
Не связан с StackOverflow