Apache - Mod重写“或重定向”

时间:2012-12-23 18:25:44

标签: mod-rewrite

我需要改写条件:

我想在网址中找到“cms”时将用户重定向到/Cms/index.php/$1,例如:http://example.com/cms/

否则我想重定向到/App/index.php/$1,我已经做了一些东西,但它给了我500错误。

RewriteEngine On
RewriteRule ^cms     /Cms/index.php/$1 [L]
RewriteRule ^.*$     /App/index.php/$1 [L]

由于

@edit

我试过但它也让我500。

error.log

[Sun Dec 23 19:40:54 2012] [error] [client 127.0.0.1] Request exceeded the limit of 10 internal redirects due to probable configuration error.vUse 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

2 个答案:

答案 0 :(得分:0)

尝试使用此代码:

RewriteEngine On
RewriteRule ^cms(.*)     /Cms/index.php/$1 [L]
RewriteRule ^(.*)$     /App/index.php/$1 [L]

答案 1 :(得分:0)

请注意,apache只运行一次重写规则。它尝试应用规则,直到url不再更改(这使得mod_rewrite非常强大)。这就是你得到错误的原因。规则正在创建重定向循环。

例如/cms/test指向/Cms/index.php/test,而/App/index.php/Cms/index.php/test又是第二条规则的匹配,导致它指向/App/index.php/App/index.php/Cms/index.php/test,此网址再次被第二条规则匹配,指示它到RewriteEngine On RewriteRule ^cms /Cms/index.php/$1 [L] RewriteCond %{REQUEST_URI} !^/(Cms|App) RewriteRule ^.*$ /App/index.php/$1 [L] 等。

要防止此循环,请添加重写条件:

{{1}}