[英]htaccess / mod_rewrite showing 404 error
我有一個非常簡單的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]
如果您的htaccess文件位於根文件夾中,而faq.php也位於根文件夾中,請嘗試以下操作:
RewriteEngine on
RewriteBase /
RewriteRule ^frequently-asked-questions/$ faq.php [NC,L]
提供服務器詳細信息的公司找到了解決方案:
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]
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.