在.htaccess中删除URL中的单词

时间:2012-05-31 18:18:58

标签: regex .htaccess url mod-rewrite redirect

经过一个多小时的搜索,我仍然无法弄清楚如何将链接从http://site/fr/other重定向到http://site/other

我正在使用此代码:

RewriteEngine On
RewriteRule ^/fr/(.*)$ /$1 [L,R=301,QSA]

2 个答案:

答案 0 :(得分:8)

只需删除第一个正斜杠:RewriteRule ^fr/(.*)$ /$1 [L,R=301,QSA]

http://htaccess.madewithlove.be/处尝试此操作。

答案 1 :(得分:2)

从网址

中删除“-xyz-”
RewriteRule ^(.*)-xyz-(.*).html$ http://%{SERVER_NAME}/$1-$2.html [NC,R=301,L]

从网址“http://yoursite.com/xyz/some-url.html

中删除“xyz”
RewriteRule ^xyz/(.*)\.html$ $1-watches.html [L,R=301]

从网址“http://yoursite.com/some-dir/xyz/some-url.html

中删除“xyz”
RewriteRule ^(.*)/xyz/(.*).html$ http://%{SERVER_NAME}/$1/$2.html [NC,R=301,L]