【发布时间】:2019-09-10 21:57:57
【问题描述】:
我有一个小型 mvc 应用程序,我试图强制 URL 从 www.example.com 转到 www.example.com/public。
为了做到这一点,我在根目录 (/) 中有一个 .htaccess 文件,然后在 /public 文件夹中有另一个 .htaccess 文件,以使用友好的 url 指向 index.php。我相信问题出在公用文件夹中的 htaccess 文件中,我需要所有请求都通过 index.php
我在 stackoverflow 上尝试了几个线程,但是当我访问 www.example.com 时似乎给了我服务器 500 错误
根目录的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /public/
</IfModule>
公用文件夹的.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}% !-f
RewriteCond %{REQUEST_FILENAME}% !-d
#allow images, css and js links
RewriteCond %{REQUEST_URI} !\.(css|js|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
【问题讨论】:
-
DirectoryIndex yourindex.php
-
我应该添加哪个部分?在根或公共 .htaccess 文件中?