【发布时间】:2012-08-26 22:43:24
【问题描述】:
我一直在为我的 mod_rewrite 苦苦挣扎,我以为我已经破解了它……
我的 CMS 使用 post.php?s= 生成博客文章 URL,我一直在尝试删除 URL 的这一部分,以使它们美观且用户友好。这是我的 mod_rewrite:
<ifModule mod_rewrite.c>
DirectoryIndex index.php index.html
ErrorDocument 404 http://tempertemper.net/error.php
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} ^www.tempertemper\.net$
RewriteCond %{REQUEST_URI} !cron.php
RewriteRule ^(.*)$ http://tempertemper.net/$1 [R=301,L]
RewriteCond %{QUERY_STRING} ^s=(.+)$
RewriteRule post.php /%1? [R=301,L]
RewriteRule ^resources /archive? [R=301,L]
RewriteCond %{REQUEST_URI} !post.php
RewriteRule ^([a-zA-Z0-9_-]+)$ post.php?s=$1
</ifModule>
不幸的是,它似乎将所有未找到的页面定向到空白 post.php 页面而不是 error.php 页面。
我的网站在这里:http://tempertemper.net,这是一个不存在的 URL http://tempertemper.net/this-url-does-not-exist
它应该带你到http://tempertemper.net/error
感谢您的浏览:)
【问题讨论】:
-
找不到页面的示例是什么?
/post.php?s=blahblah? -
嗨 @Jon,CMS 生成 example.com/post.php?s=blahblah,我将其重写为 example.com/blahblah
-
但是它怎么知道
blahblah没有找到呢?
标签: php .htaccess mod-rewrite http-status-code-404 http-status-code-301