htaccess / mod_rewrite显示404错误

时间:2014-10-09 08:39:35

标签: php apache .htaccess mod-rewrite

我有一个非常简单的htaccess文件来重写页面URL。

例如我有

RewriteRule ^frequently-asked-questions faq.php [L]

我遇到的问题是,当我导航到domain.com/frequently-asked-questions时,它会向我显示404,如下所示:

The requested URL /domain.com/frequently-asked-questions was not found on this server.

导航到domain.com/faq.php有效。

关键是,它似乎是在404错误中添加了域名,并且它没有意识到它必须寻找/faq.php - 尽管我猜想如果我可以摆脱前者(来自404的域名)将解决后者。

完整的htaccess:

RewriteEngine On
RewriteBase /

RewriteRule ^landowners landowners.php [L]
RewriteRule ^frequently-asked-questions faq.php [L]
RewriteRule ^contact contact.php [L]
RewriteRule ^company company.php [L]

2 个答案:

答案 0 :(得分:0)

如果您的htaccess文件位于根文件夹中且faq.php也位于根文件夹中,请尝试以下操作:

RewriteEngine on
RewriteBase /

RewriteRule ^frequently-asked-questions/$ faq.php [NC,L]

答案 1 :(得分:0)

提供服务器详细信息的公司找到了解决方案:

RewriteEngine on
Options +FollowSymLinks -MultiViews

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/$ $1.php 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule (.*)$ /$1/ [R=301,L]