2012-10-22 145 views
1

非常简单的问题。我需要改变URL像.htaccess重定向,更改GET变量

http://www.mysite.com/index.php?page=[x] 

其中[x]是任意数字至

http://www.mysite.com/index.php?id=[x] 

只是改变?页=什么?ID =使用的.htaccess 301重定向。

我该怎么做?

回答

2

匹配的QUERY_STRINGRewriteCond

RewriteEngine On 
# Capture (\d+) into %1 
RewriteCond %{QUERY_STRING} page=(\d+) [NC] 
# And rewrite (redirect) into id=%1 
RewriteRule ^index\.php$ /index.php?id=%1 [L,R=301] 

以上只会改写请求index.php。如果你想重写的一切,改为使用

RewriteRule ^(.*)$ /$1?id=%1 [L,R=301]