Home > Backend Development > PHP Tutorial > php使用apache的rewrite规则把访问链接转换的问题?

php使用apache的rewrite规则把访问链接转换的问题?

WBOY
Release: 2016-06-06 20:32:11
Original
1018 people have browsed it

比如:


http://www.xxx.com/x/index.html
http://www.xxx.com/x/index.html?b1=y&b2=z&....
http://www.xxx.com/x/question.html
http://www.xxx.com/x/question.html?b1=y&b2=z&....

怎么写rewrite规则,把上面的转换为下面的链接:(就是把a1这个参数的值改为问号后面参数传入)


http://www.xxx.com/index.php?a1=x
http://www.xxx.com/index.php?a1=x&b1=y&c1=z&....
http://www.xxx.com/question.php?a1=x
http://www.xxx.com/question.php?a1=x&b1=y&c1=z&....

回复内容:

比如:


http://www.xxx.com/x/index.html
http://www.xxx.com/x/index.html?b1=y&b2=z&....
http://www.xxx.com/x/question.html
http://www.xxx.com/x/question.html?b1=y&b2=z&....

怎么写rewrite规则,把上面的转换为下面的链接:(就是把a1这个参数的值改为问号后面参数传入)


http://www.xxx.com/index.php?a1=x
http://www.xxx.com/index.php?a1=x&b1=y&c1=z&....
http://www.xxx.com/question.php?a1=x
http://www.xxx.com/question.php?a1=x&b1=y&c1=z&....

我写一个index.html的规则,question.html的题主照着自己写一下吧。
RewriteRule ^/x/index.html$ /index.php?a1=x [NC,L]
RewriteRule ^/x/index.html\?([^\/])+$ /index.php?a1=x&$1 [NC,L]

用正则匹配的反向引用,用这种方法其实a1,b1,c1三个参数都可以写到RewriteRule里的,前面伪静态后边是查询字符串是不是有点怪怪的。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template