与多个查询字符串mod_rewrite的? [英] mod_rewrite with multiple query strings?

查看:102
本文介绍了与多个查询字符串mod_rewrite的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图清理一些网址在我的博客,所以我决定看看mod_rewrite的。我没有一个线索我在做什么的,所以我希望我能得到一些帮助:PI有像 http://kn3rdmeister.com/blog/post.php?y=2012&链接M = 07和D = 04和ID = 4 。虽然它的工作原理,人们仍然可以得到我希望他们有内容,我不喜欢他们不必看所有的查询字符串。我想打开上面的链接进入 http://kn3rdmeister.com/blog/2012/07/04/4.php

I'm trying to cleanup some URLs on my blog, so I've decided to look into mod_rewrite. I haven't a clue what I'm doing though, so I was hoping I could get some help :P I have links like http://kn3rdmeister.com/blog/post.php?y=2012&m=07&d=04&id=4. Although it works, and people still get the content I want them to have, I don't like them having to look at all the query strings. I want to turn the above link into http://kn3rdmeister.com/blog/2012/07/04/4.php.

这是我的.htaccess看起来像现在。

This is what my .htaccess looks like right now.

RewriteEngine On
RewriteCond %{QUERY_STRING} ^y=([0-9){4})&m=([0-9]{2})&d=([0-9]{2})&id=([0-9]*)$
RewriteRule ^/blog/post\.php$ http://kn3rdmeister.com/blog/%1/%2/%3/%4.php? [L]

就像我说的,我绝对无言以对:D

Like I said, I'm absolutely clueless :D

推荐答案

如果你使用Apache 2.0或更高版本,你将需要删除的斜线(在preFIX),如果这些规则是.htaccess文件,让你的正常的前pression看起来是这样的:

If you're using apache 2.0 or higher, you're going to need to remove the leading slash (the prefix) if these rules are in an .htaccess file, so that your regular expression looks like this:

# also note this needs to be a "]"--v
RewriteCond %{QUERY_STRING} ^y=([0-9]{4})&m=([0-9]{2})&d=([0-9]{2})&id=([0-9]*)$
RewriteRule ^blog/post\.php$ http://kn3rdmeister.com/blog/%1/%2/%3/%4.php? [L]

这是要使它所以当有人把 http://kn3rdmeister.com/blog/post.php?y=2012&m=07&d=04&id=4 在其浏览器的地址栏中的URL,浏览器将被重定向到 http://kn3rdmeister.com/blog/2012/07/04/4.php 而新的URL会出现在他们的地址栏。

This is going to make it so when someone puts http://kn3rdmeister.com/blog/post.php?y=2012&m=07&d=04&id=4 in their browser's URL address bar, their browser will get redirected to http://kn3rdmeister.com/blog/2012/07/04/4.php and the new URL will appear in their address bar.

我想你已经得到的东西设置您的服务器来处理像一个请求博客/ 2012/07/04 / 4.php

I assume you've got something setup on your server to handle a request like blog/2012/07/04/4.php.

这篇关于与多个查询字符串mod_rewrite的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆