【问题标题】:How to configure .htaccess for subdirectory如何为子目录配置 .htaccess
【发布时间】:2019-08-31 16:13:23
【问题描述】:

我有一个托管在 AWS 上的 WordPress 网站,我很难配置 mod_rewrite 以使其正常工作。

文件夹结构

/root
  |_ staging/
  |_ live/

.htaccess 是 WordPress 的默认值

<IfModule mod_rewrite.c>

  RewriteEngine On
  RewriteBase /
  RewriteRule ^index\.php$ - [L]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule . /index.php [L]

</IfModule>

主要问题

我可以访问/staging/index.php/api,而我以前没有像---.com/api 这样的子目录来访问它。

当我尝试/staging/api 时,它显示File not found

我尝试将.htaccess 更改为不同的东西,但都没有成功。

根目录下没有.htaccess文件。

我们将不胜感激 =)

提前致谢。

【问题讨论】:

    标签: php wordpress mod-rewrite apache2


    【解决方案1】:

    试试这个代码

    <IfModule mod_rewrite.c>
    
      RewriteEngine On
      RewriteBase /staging
      RewriteRule ^index\.php$ - [L]
      RewriteCond %{REQUEST_FILENAME} !-f
      RewriteCond %{REQUEST_FILENAME} !-d
      RewriteRule . /staging/index.php [L]
    
    </IfModule>
    

    注意:AllowOverride 应在服务器配置中设置为 All。 你可以从这里找到参考。 How to Set AllowOverride all

    【讨论】:

    • 我确实在/staging/.htaccess 中尝试过,但没有成功
    • 你能分享你的.htaccess代码你是如何修改的吗?或者尝试将这一行 RewriteBase /staging 更新为 RewriteBase /staging/
    • ``` # BEGIN WordPress RewriteEngine On RewriteBase /staging/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 重写规则。 /staging/index.php [L] # END WordPress ``` 那是新的.htaccess 文件我已经尝试过/staging/staging/
    • 奇怪的东西。我正在使用相同的产品并为我工作。如果一切正常,您是否在服务器配置中检查过这一点? stackoverflow.com/questions/18740419/… 另外可以分享一下你的服务器配置吗?
    • 我更改了主要 apache 配置中的 AllowOverride 并且它起作用了。非常感谢
    猜你喜欢
    • 2021-05-10
    • 1970-01-01
    • 1970-01-01
    • 2013-09-16
    • 2017-01-23
    • 1970-01-01
    • 2020-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多