【问题标题】:multiple domains with htaccess rewrite rule具有 htaccess 重写规则的多个域
【发布时间】:2014-06-14 13:19:38
【问题描述】:

我无法让 htaccess 与子域一起工作。
我的服务器结构:

root / index.php ---//codeigniter 索引文件,对于应用程序 A,主域指向此处。
root/staging/StagingWebsite ---// 我的子域指向此处。
StagingWebsite 文件夹有一个名为 temp.html
的文件 继续前进,我的根 htaccess 文件是这样的:

RewriteEngine on
RewriteCond 
RewriteCond $1 ^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

这会将对 MyDomain/foo 的任何访问权限转换为 MyDomain/index.php/foo。 (不显示 index.php)。

问题:
当我尝试访问我的subdomain/temp.html 时,我得到一个500 internal error
当我删除我的root/.htaccess 时,它工作正常。所以这显然是我的 htaccess 文件。

我发现问题是 root/.htaccess 规则被应用于子域,这破坏了一切,但我不知道如何解决。

我在root/staging/StagingWebsite 中放置了一个空的.htaccess 文件,希望它会覆盖之前的任何htaccess 设置,但这不起作用。

编辑
我专门解决了这个问题,但我不喜欢这个解决方案。
我添加了一个 RewriteCond 以仅针对特定域运行重写规则。
有没有办法在不指定域的情况下解决这个问题?

【问题讨论】:

    标签: apache .htaccess codeigniter mod-rewrite subdomain


    【解决方案1】:

    仅使用此行创建 /root/staging/StagingWebsite/.htaccess

    RewriteEngine on
    

    这将覆盖任何父级的重写规则。

    【讨论】:

    • 谢谢,空的 htaccess 不起作用有什么原因吗?
    • 是的,空 .htaccess 不会覆盖来自父 .htaccess 的重写规则,但添加 RewriteEngine on 就可以了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-15
    • 2017-11-21
    • 2013-06-29
    • 1970-01-01
    • 2011-08-14
    相关资源
    最近更新 更多