使用htaccess的重写URL [英] rewrite url using htaccess

查看:289
本文介绍了使用htaccess的重写URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用htaccess的可以更改URL以这种方式:

http://example.com/page.php?go= 东西的.php

应该被重定向到:

http://example.com/ 的东西

如果把GET参数的名称比走出去离开,因为它是不同的...

解决方案

这应该做的:

 #假设RewriteEngine叙述上已被称为
的RewriteCond%{QUERY_STRING} ^(*&安培;。)去=([AZ] +)\ PHP(安培;。*)?。?$
重写规则page.php%2?
 

在这里有什么会发生?首先,的RewriteCond包含查询字符串相匹配的去= something.php ,其中东西是由捕获(即[az] +)。然后重写规则使用来自的RewriteCond第二捕获组的内容,含有something.php。问号在年底摆脱了原来的查询字符串。

请注意:如果你想preserve查询字符串中不包括去= ... 参数的休息,事情就变得复杂了一点。

http://httpd.apache.org/docs/的文档2.2 / MOD / mod_rewrite.html 获取更多的信息。

How can I change url in this way using htaccess:

http://example.com/page.php?go=something.php

should be redirected to:

http://example.com/something

If the get parameter name is different than 'go' leave as it is...

解决方案

This should do:

# Assuming that "RewriteEngine On" has already been called
RewriteCond %{QUERY_STRING} ^(.*&)?go=([a-z]+)\.php(&.*)?$
RewriteRule page.php %2?

What happens here? First, RewriteCond matches a query string that contains the go=something.php, where "something" is captured by ([a-z]+). Then the RewriteRule uses the second capture group's contents from RewriteCond, containing "something.php". The question mark at the end gets rid of the original query string.

Note: if you want to preserve the rest of the query string excluding go=... parameter, things get a bit more complicated.

See the docs in http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html for more info.

这篇关于使用htaccess的重写URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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