【发布时间】:2014-08-08 01:04:59
【问题描述】:
我有这个重定向 htaccess 代码将 file.php 更改为 /file/,因此 URL 对 SEO 更友好。
RewriteEngine On
# hide .php extension snippet
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1/ [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
但是,当有人输入错误的网址时,例如 - domain.com/file/whateverblablabla-wrong
我收到内部服务器错误。
我希望它重定向到主页,或者如果我为 404 页面选择特定的 URL,这样我就可以拥有站点地图或其他东西......
非常感谢, -O
【问题讨论】:
-
这些规则不会产生内部错误。检查您的 Apache error.log 以查看实际错误。
-
不确定是不是这样:[Thu Aug 07 08:48:19 2014] [error] [client 24.186.15.215] 由于可能的配置错误,请求超出了 10 个内部重定向的限制。如有必要,使用“LimitInternalRecursion”增加限制。使用“LogLevel debug”获取回溯。
标签: php apache .htaccess mod-rewrite redirect