【问题标题】:.htaccess -> index.php in web folder (url has to be web/).htaccess -> web 文件夹中的 index.php(网址必须是 web/)
【发布时间】:2015-04-24 12:52:19
【问题描述】:

我在设置 .htaccess 文件时遇到问题。在我的 web 文件夹中(在我的项目的 root 中)我有 index.php 。现在我必须去 mydomain.com/web/ 看看我的 index.php 。

我在我的 /web 文件夹中添加了一个 .htacces 文件,但它不起作用。这是我的 .htaccess 文件的内容:

<IfModule mod_rewrite.c>
   RewriteEngine On

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>

我做错了什么?

【问题讨论】:

    标签: php apache .htaccess mod-rewrite rewrite


    【解决方案1】:

    您可以为此拥有 2 个 .htaccess:

    root .htaccess(高于网页的一级):

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^((?!web/).*)$ web/$1 [NC,L]
    

    /web/.htaccess:

    RewriteEngine On
    RewriteBase /web/
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) index.php [L]
    

    【讨论】:

    • 这给了我错误:您无权访问此服务器上的 /。
    • 你能从 Apache 配置中检查你的实际 DocumentRoot 吗?
    • 我如何检查这个?试图找到 /etc/apache2/conf/httpd.conf 但 httpd.conf 不存在。
    【解决方案2】:

    你试过RewriteBase吗?

    RewriteBase /web/
    

    这篇文章也很有帮助

    【讨论】:

    • 尝试添加但结果相同
    • @nielsv,如果你尝试像这样RewriteRule ^([^?]*)$ index.php?path=$1 [NC,L,QSA] 会怎样。 .htaccess 应该在 index.php 所在的文件夹中。或者 RewriteRule ^([^?]*)$ /web/index.php?path=$1 [NC,L,QSA] 如果 .htaccess 位置是 root
    猜你喜欢
    • 2017-01-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-09
    相关资源
    最近更新 更多