【问题标题】:FIXED htaccess rewriterule gives 404 error固定 htaccess rewriterule 给出 404 错误
【发布时间】:2015-06-25 15:18:21
【问题描述】:

我正在尝试将 /test 重写为 /test.php。如果我直接转到链接,它会给我有效的 php 页面,但是当我转到 /test 时,它只会给出 404 not found 错误。我已启用 mod_rewrite 并授予 /var/www 755 权限。

.htaccess

RewriteEngine On
RewriteRule ^test test.php [NC]

test.com.conf

<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName test.com
ServerAlias www.test.com

DocumentRoot /var/www/test.com
<Directory />
    Options FollowSymLinks
    AllowOverride All
</Directory>
<Directory /var/www/test.com>
    Options Indexes FollowSymLinks MultiViews
    AllowOverride All
    Order allow,deny
    allow from all
</Directory>

ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
<Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
</Directory>

ErrorLog ${APACHE_LOG_DIR}/error.log

# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn

CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

修复:将 FollowSymLinks 更改为 +FollowSymLinks

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    如果你使用RewriteLogLevel,你会看到服务器做了什么。在您的情况下,您将看到 applying pattern '^test' to uri '/test'。将您的规则更新为:

    RewriteRule ^/test$ /test.php [NC]
    

    【讨论】:

    • 还是找不到文件
    • 激活重写日志以准确查看您的服务器做了什么以及为什么它不匹配。我在发布答案之前在我的服务器上测试了这个,你应该接近你的解决方案。
    • 在此日志中,您尝试加载与 ^/?test.html$ 不匹配的 test.php。你的问题不是关于加载/test 和访问/test.php 吗?
    猜你喜欢
    • 2023-03-03
    • 1970-01-01
    • 2015-09-28
    • 1970-01-01
    • 2015-07-18
    • 2022-09-22
    • 2018-06-18
    • 2022-12-10
    • 2012-11-10
    相关资源
    最近更新 更多