问题
I'm using RewriteRule
in my URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?lang=$1&page=$2 [L,QSA,NC]
Now I need to create a 301 redirect. So I do that:
Redirect 301 /port/reestruturacao-financeira http://website.com/port/reestruturacao-corporativa/
The result is wrong:
http://website.com/port/reestruturacao-corporativa//?lang=port&page=reestruturacao-financeira
How can I fix that? redirect
http://website.com/port/reestruturacao-corporativa/
to
http://website.com/port/reestruturacao-corporativa/
回答1:
You need to keep redirect 301
rule before other internal rewrite rule and use only mod_rewrite
rules:
RewriteEngine On
RewriteRule ^port/reestruturacao-financeira /port/reestruturacao-corporativa/? [L,NC,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?lang=$1&page=$2 [L,QSA]
Don't forget to clear your browser cache before testing.
来源:https://stackoverflow.com/questions/37048311/htaccess-redirect-with-url-friendly-mod-rewrite