页面不存在时发生内部服务器错误
问题描述:
我刚刚意识到,如果您要在网站栏中手动输入网站上不存在的页面,则该站点会响应一个内部服务器错误。页面不存在时发生内部服务器错误
是不是404页面未找到?
我的网站是http://www.cristianrgreco.com,例如http://www.cristianrgreco.com/example将返回一个服务器错误。
这是我经常在遇到.htaccess文件时遇到的错误,所以我在下面张贴了我的。
RewriteEngine On
Options +FollowSymLinks
# Add WWW to URL
RewriteCond %{HTTP_HOST} ^cristianrgreco\.com$ [NC]
RewriteRule ^(.*)$ http://www.cristianrgreco.com/$1 [L,R=301]
# Remove trailing slashes from end of URL
RewriteCond %{HTTP_HOST} !^\.cristianrgreco\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [L,R=301]
# Rewrite article URLs
RewriteRule ^articles/([a-zA-Z0-9_-]+)/?$ articles.php?article=$1
# Remove file extension from PHP files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L,QSA]
在此先感谢您的帮助。
答
我以前也遇到过这个问题,但问题是这条线
RewriteRule ^(.*)$ $1.php [L,QSA]
与RewriteRule ^([^\.]+)$ $1.php [NC,L,QSA]
替换它似乎待办事项的伎俩。括号中的括号表示任何匹配的内容都会被RewriteRule记住。括号内,它说:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
# Add WWW to URL
RewriteCond %{HTTP_HOST} ^cristianrgreco\.com$ [NC]
RewriteRule ^(.*)$ http://www.cristianrgreco.com/$1 [L,R=301]
# Remove trailing slashes from end of URL
RewriteCond %{HTTP_HOST} !^\.cristianrgreco\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [L,R=301]
# Rewrite article URLs
RewriteRule ^articles/([a-zA-Z0-9_-]+)/?$ articles.php?article=$1
# Remove file extension from PHP files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^([^\.]+)$ $1.php [NC,L,QSA]
</IfModule>
+0
绝对的辉煌,永远都不会想到我自己。非常感谢! – Cristian
您可以试试[临站长(http://webmasters.stackexchange.com/)来代替。 –