添加斜杠时获取500错误而不是404错误

时间:2014-03-20 14:54:47

标签: regex apache .htaccess mod-rewrite web

我没有找到导致此错误的规则,我的.htaccess是:

RewriteEngine on
Options -Multiviews


RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^ru\/index\.php$ "http\:\/\/www\.example\.com\/ru\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^en\/index\.php$ "http\:\/\/www\.example\.com\/en\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^it\/index\.php$ "http\:\/\/www\.example\.com\/it\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^fr\/index\.php$ "http\:\/\/www\.example\.com\/fr\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^de\/index\.php$ "http\:\/\/www\.example\.com\/de\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^uk\/index\.php$ "http\:\/\/www\.example\.com\/uk\/" [R=301,L]

RewriteCond %{HTTP_HOST} ^example\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^es\/index\.php$ "http\:\/\/www\.example\.com\/es\/" [R=301,L]

RewriteCond %{THE_REQUEST} \.php [NC]
RewriteRule \.php$ - [L,R=404,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

ErrorDocument 404 /en/404.php
ErrorDocument 403 /error_page.html
ErrorDocument 500 /error_page.html

当我尝试打开不存在的页面时 - 它给了我404错误,但如果我将“/”添加到现有页面 - 内部服务器错误+错误打开/error_page.html文件...为什么?< / p>

的exaple:

http://www.example.com/en/cinque-terre-beaches - real page
http://www.example.com/en/cinque-terre-beachesfdsfs/ - 404
http://www.example.com/en/cinque-terre-beaches/ - 500

谢谢!

1 个答案:

答案 0 :(得分:0)

将您的php规则更改为:

RewriteCond %{THE_REQUEST} \.php [NC]
RewriteRule \.php$ - [L,R=404,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteRule ^(.+?)/?$ $1.php [L]

在其他R=301规则之后移动它。