【问题标题】:How to forward root request to another directory with htaccess?如何使用 htaccess 将 root 请求转发到另一个目录?
【发布时间】:2017-09-08 08:00:02
【问题描述】:

我有一个只有测试index.php 文件和.htaccess 的根目录。您能否帮助将根请求(example.com)转发到子目录(example.com/wp/index.php)。我不需要任何重定向,因为它们会更改地址栏中的 URL。

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule $^ /wp/index.php [L]
</IfModule>

现在是我在根目录中的.htaccess 文件。有了.htaccess,服务器只返回/index.php(根索引,而不是子目录)。

所以我不认为这是一个很难的问题,但我找不到我在哪里犯错误。

【问题讨论】:

    标签: php wordpress apache .htaccess mod-rewrite


    【解决方案1】:
    RewriteRule $^ /wp/index.php [L]
    

    您的正则表达式锚点(字符串结尾$ 和字符串开头^)绕错了方向。但是,如果您设置了 DirectoryIndex,也可能会遇到问题(mod_dir 将触发 /index.php 的内部子请求,因此 URL 路径不一定为空)。

    请尝试以下方法:

    RewriteEngine On
    RewriteRule ^(index\.php)?$ /wp/index.php [L]
    

    RewriteRule 模式 ^(index\.php)?$ 匹配空 URL 路径或 index.php(mod_dir 子请求的结果)。

    不需要&lt;IfModule&gt; 容器并且这里没有使用RewriteBase

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-08
      • 1970-01-01
      • 1970-01-01
      • 2020-03-02
      • 2017-02-04
      • 1970-01-01
      • 2011-09-11
      相关资源
      最近更新 更多