在.htaccess中删除URL中的单词

use*_*736 3 regex url .htaccess mod-rewrite redirect

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

我正在使用此代码:

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

cre*_*ama 8

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

http://htaccess.madewithlove.be/试试这个.

  • 哎呀,抱歉。我删除了组合的一个(`RewriteRule ^fr((?:/.*$)?) $1 [L,R=301,QSA]`),因为`http://site/france`会重定向到`http://site/france` /site/ance`,我认为这不是预期的行为。 (2认同)
  • 好吧,这个组合规则可能会更好:`RewriteRule ^fr((?:(?:\s*|/.*)$)) $1 [L,R=301,QSA]`。`http://site/france` 不会重定向到 `http://site/ance`;`http://site/fr ` 重定向到 `http://site/`;`http://site/fr/` 重定向到 `http://site/`;`http://site/fr/other` 重定向到 `http://site/other`。 (2认同)