在每个 URL mod_rewrite Apache 前面添加别名



如果有任何喜欢的格式

http://localhost/index.php/bla...

我想将其转换为http://localhost/er/index.php/bla...

我正在尝试以下内容,但它似乎无限期地循环 url

RewriteRule  ^localhost/index/php/(.*)$  localhost/er/index.php/$1  [R=301,L]
RedirectMatch  301  ^/localhost/index.php/(.*)$  localhost/er/index.php/$1

你有2个不同的事情发生,一个RewriteRule(mod_rewrite)和一个RedirectMatch(mod_alias)。您只需要一个,但这两个都不能与主机名(本地主机)匹配。如果这必须仅限于"本地主机"主机,那么您需要执行以下操作:

RewriteEngine On
RewriteCond %{HTTP_HOST} localhost$ [NC]
RewriteRule ^/?index.php/(.*)$ /er/index.php/$1 [R=301,L]

否则,你可以坚持mod_alias:

Redirect 301 /index.php/ /er/index.php/

/index.php/之后的所有内容都将自动附加。

最新更新