如何为子目录配置.htaccess

时间:2019-04-10 08:57:20

标签: php wordpress mod-rewrite apache2

我在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文件。

一些帮助将不胜感激=)

谢谢。

1 个答案:

答案 0 :(得分:0)

尝试此代码

<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 设置为全部。 您可以从这里找到参考。 How to Set AllowOverride all