开发者

rewrite url using htaccess

How can I change url in this way using htaccess:

开发者_JAVA百科

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.


something like this (google around for the correct syntax)

RewriteEngine On
RewriteBase /
RewriteRule ^page.php?go=login.php /login [L]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜