简体   繁体   English

.htaccess重写= 404页

[英].htaccess rewrite = 404 page

I want to make for example www.mydomain.com/about.php to www.mydomain.com/about. 我想将www.mydomain.com/about.php设为www.mydomain.com/about。

Based on some blog reading, 根据一些博客读物,

Here what I have on my httpd.conf 这是我在httpd.conf中拥有的内容

<Directory "var/www/mydomain">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Allow from all
Order allow, deny
RewriteEngine On
</Directory>

My .htaccess file 我的.htaccess文件

Order deny,allow
DirectoryIndex index.php

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -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]

www.mydomain.com/about.php still works but the /about has 404 URL Not Found page. www.mydomain.com/about.php仍然可以使用,但是/ about包含404 URL Not Found页面。

Is there something wrong with the above configuration? 上面的配置有问题吗?

In your last line, try: 在最后一行中,尝试:

RewriteRule ^(.*)$     $1.php [L]

(note the ^ and the removed R=301) (注意^和删除的R = 301)

If it doesn't work, try removing all previous lines in your .htaccess file. 如果它不起作用,请尝试删除.htaccess文件中的所有先前行。 Only keep RewriteEngine On only. 仅使RewriteEngine On保持RewriteEngine On

Your first two RewriteRules mandate that there be a / after the name, as the last character. 您的前两个RewriteRules要求在名称后有一个/作为最后一个字符。 You probably want to make that optional: 您可能希望使其成为可选:

RewriteRule ^([^/]+)/?$ $1.php
RewriteRule ^([^/]+)/([^/]+)/?$ /$1/$2.php

That may be why you're not matching /about in the first rewrite group. 这可能就是为什么您在第一个重写组中不匹配/ about的原因。 I presume you're trying to do something different in the second rewrite group, but it's not clear what (hint: a comment or two on what you're doing would be quite helpful). 我猜想您正在第二重写组中尝试做一些不同的事情,但尚不清楚是什么(提示:对您正在做的事情发表一两个评论会很有帮助)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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