简体   繁体   English

htaccess / mod_rewrite显示404错误

[英]htaccess / mod_rewrite showing 404 error

I have a very simple htaccess file in place to rewrite the page URL's. 我有一个非常简单的htaccess文件来重写页面URL。

For example I have 例如我有

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

The problem I am having is that when I navigate to domain.com/frequently-asked-questions it shows me a 404 as follows: 我遇到的问题是,当我导航到domain.com/frequently-asked-questions它显示给我一个404信息,如下所示:

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

Navigating to domain.com/faq.php works. 导航至domain.com/faq.php

The point is, it seems to be adding the domain name in the 404 error and it isn't recognising that it has to be looking for /faq.php - although I'm guessing that if I can get rid of the former (the domain name from the 404) it will solve the latter part. 关键是,它似乎正在404错误中添加域名,并且它没有意识到它必须在查找/faq.php尽管我猜测如果我可以摆脱前者( 404域名)将解决后一部分。

Full htaccess: 完整的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]

If your htaccess file is in root folder and faq.php is also in root folder, try the following: 如果您的htaccess文件位于根文件夹中,而faq.php也位于根文件夹中,请尝试以下操作:

RewriteEngine on
RewriteBase /

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

The company providing the server details found a solution: 提供服务器详细信息的公司找到了解决方案:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM