mod_rewrite 路径信息后缀和每个目录前缀

mod_rewrite 路径信息后缀和每个目录前缀

.htaccess 配置存在问题。

我只需要网址/类别匹配类别.php脚本,但是当我尝试打开此 url 时,却出现 404 错误。

这是我的.htaccess:

RewriteEngine on
RewriteRule ^category/ category.php [QSA,L]

htaccess 日志:

init rewrite engine with requested uri /category/
[www.test.com/sid#7fc1c2694dd0][rid#7fc1c25f00a0/initial] pass through /category/
[www.test.com/sid#7fc1c2694dd0][rid#7fc1c25e80a0/subreq] [perdir /home/ubuntu/domains/test.com/public_html/] add path info postfix: /home/ubuntu/domains/test.com/public_html/category.php -> /home/ubuntu/domains/test.com/public_html/category.php/
[www.test.com/sid#7fc1c2694dd0][rid#7fc1c25e80a0/subreq] [perdir /home/ubuntu/domains/test.com/public_html/] strip per-dir prefix: /home/ubuntu/domains/test.com/public_html/category.php/ -> category.php/
[www.test.com/sid#7fc1c2694dd0][rid#7fc1c25e80a0/subreq] [perdir /home/ubuntu/domains/test.com/public_html/] applying pattern '^category/' to uri 'category.php/'
[www.test.com/sid#7fc1c2694dd0][rid#7fc1c25e80a0/subreq] [perdir /home/ubuntu/domains/test.com/public_html/] pass through /home/ubuntu/domains/test.com/public_html/category.php

结果是 Apache 出现 404 错误:未找到

该服务器上未找到所请求的 URL /category/。

如果我打开/category.php直接,它可以工作。

这是虚拟主机配置:

<VirtualHost *:80>
    ServerName test.com
    ServerAlias www.test.com

    ServerRoot /home/ubuntu/domains/test.com
    DocumentRoot public_html
    <Directory "/home/ubuntu/domains">
        Options FollowSymLinks MultiViews
        AllowOverride all
        Require all granted
    </Directory>

    RewriteEngine On
    LogLevel alert rewrite:trace3

    ErrorLog logs/error.log
    CustomLog logs/access.log combined

        AddOutputFilterByType DEFLATE text/html text/plain text/xml text/css text/javascript application/javascript application/json
        DeflateCompressionLevel 9
</VirtualHost>

服务器版本:Apache/2.4.7(Ubuntu)

服务器建立时间:2014 年 7 月 22 日 14:36:38

答案1

我遇到了类似的问题并更换了

Options MultiViews

Options  -MultiViews

事实上我最终

Options +Indexes +FollowSymLinks -MultiViews

我在这里找到了解决方案:

https://velenux.wordpress.com/2012/07/17/apache-mod_rewrite-multiple-add-path-info-postfix/

相关内容