【发布时间】:2012-05-19 16:41:12
【问题描述】:
我知道这里有数百篇关于 htaccess 的帖子,但我似乎找不到与我的情况相符的帖子。
我有两个重写规则发生:
第一个将 example.com/filename.php 转换为 example.com/filename/ 以及将 example.com/filenameA-filenameB.php 转换为 example.com/filenameA/filenameB/
第二个在请求的 URL 的末尾添加一个斜杠(如果没有的话)。
一切都很好...直到您输入错误的 URL,例如 example.com/foo 或 example.com/foo/ 其中 foo.php 不存在。我得到“页面没有正确重定向”并且地址栏显示“example.com/foo.php.php.php.php.php.php.php.php ...”。我只想得到一个 404,这样我就可以重定向到 404 页面,但我尝试的任何方法似乎都不起作用。
感谢您的帮助!
RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/(.+)//?$ $1-$2.php [NC,L]
RewriteRule ^(.+)//?$ $1.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://example.com/$1/ [L,R=301]
【问题讨论】:
-
//?应该做什么?