【问题标题】:Using mod_rewrite to replace RewriteBase with a RewriteCond for base directory使用 mod_rewrite 将 RewriteBase 替换为基目录的 RewriteCond
【发布时间】:2017-03-26 11:51:38
【问题描述】:

我在尝试为生产/实时环境设置多个 RewriteBase 目录时遇到问题。我已按照以下网址提供的指导进行操作:

Many RewriteBase in one .htaccess file?

With mod_rewrite can I specify a RewriteBase within a RewriteCond?

这似乎可以广泛使用,除非基本目录是根目录(即“/”),如下所示:

RewriteCond %{HTTP_HOST} ^localhost/tla-test/(.)$ [OR]
RewriteCond %{HTTP_HOST} ^192.168.0.200/tla-test/(.)$
RewriteRule ^(.*)$ tla-test/index.php&page=$1 [L]

RewriteCond %{HTTP_HOST} ^test.townshendla.com/(.)$
RewriteRule ^(.*)$ /index.php&page=$1 [L]

#Send any reqests to the index.php file
RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule .*                     index.php

第一个重写条件完美运行。第二个重写条件在启动时不断出现错误 500。因为它是 1and1,所以我无法获取 Apache 错误日志,但如果我尝试在测试环境中复制,我会收到以下错误(请注意这可能无关):

AH00124:请求超出了 10 个内部重定向的限制,原因是 可能的配置错误。使用“LimitInternalRecursion”增加 必要时限制。使用“LogLevel debug”获取回溯。

任何想法将不胜感激。

【问题讨论】:

标签: apache .htaccess mod-rewrite


【解决方案1】:

感谢您的帮助。首先,anubhava,您对 HTTP_HOST 的看法是正确的,其次,您的指针非常宝贵,它引导我访问此页面,并详细解释了遇到类似问题的人:

Mod_Rewrite unexpected behavior L flag

总的来说,问题似乎是文件/目录检查进入了一个循环,似乎解决这个问题的代码是:

RewriteCond %{HTTP_HOST} ^(localhost|192.168.0.200)$
RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule ^(.*)$ /tla-test/index.php?page=$1

RewriteCond %{HTTP_HOST} !^(localhost|192.168.0.200)$
RewriteCond %{REQUEST_FILENAME}    !-f
RewriteCond %{REQUEST_FILENAME}    !-d
RewriteRule ^(.*)$ /index.php?page=$1

谢谢

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 1970-01-01
    • 2010-11-22
    • 2016-01-08
    • 2016-02-28
    • 1970-01-01
    • 2015-05-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多