2012-10-22 131 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]