我有一个要更改的 RewriteRule 设置http://kn3rdmeister.com/blog/post.php?y=2012&m=07&d=04&id=4
进入http://kn3rdmeister.com/blog/2012/07/04/4.php
但这实际上重定向了浏览器从哪里获取页面。我还想显示/blog/post.php?y=xxxx&m=xx&d=xx&id=xx
但让浏览器显示更简单的 URL,如/blog/post/year/month/day/id.php
我在某处阅读了有关使用 ProxyPass 的内容,但我不太清楚自己在做什么:P
我希望人们能够访问带有查询字符串的 post.php URL,或者带有日期的花哨的 shmancy 子目录的干净 URL 并获得相同的内容——同时最后显示干净的 URL。
最佳答案
你想要这样的东西:
# First if someone actually requests a /blog/post.php URL, redirect them
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD)\ /blog/post\.php\?y=([0-9]{4})&m=([0-9]{2})&d=([0-9]{2})&id=([0-9]*)\ HTTP/
RewriteRule ^blog/post\.php$ /blog/%2/%3/%4/%5.php [R=301,L]
这会将浏览器重定向到
/blog/##/##/##/##.php
URI,这将显示在他们的地址栏中。一旦它们被重定向,浏览器就会发送一个对 /blog/##/##/##/##.php
的请求。然后你的服务器需要在内部重写它 返回 :# We got pretty URLs, but need to rewrite back to the php request
RewriteRule ^blog/([0-9]{4})/([0-9]{2})/([0-9]{2})/([^\.]+)\.php$ /blog/post.php?y=$1&m=$2&d=$3&id=$4 [L]
这会在内部更改所有内容,以便文件/blog/post.php 可以处理请求。
关于.htaccess - 使用 .htaccess 更改显示的 URL,但不实际重定向内容?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11402153/