.htaccess redirect with URL friendly (mod_rewrite)

独自空忆成欢 提交于 2021-01-28 21:26:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!