【发布时间】:2012-10-22 15:25:35
【问题描述】:
很简单的问题。我需要更改网址,例如
http://www.mysite.com/index.php?page=[x]
其中 [x] 是任意数字
http://www.mysite.com/index.php?id=[x]
只需使用 .htaccess 301 重定向将 ?page= 更改为 ?id=。
我该怎么做?
【问题讨论】:
标签: .htaccess variables redirect get
很简单的问题。我需要更改网址,例如
http://www.mysite.com/index.php?page=[x]
其中 [x] 是任意数字
http://www.mysite.com/index.php?id=[x]
只需使用 .htaccess 301 重定向将 ?page= 更改为 ?id=。
我该怎么做?
【问题讨论】:
标签: .htaccess variables redirect get
在RewriteCond 中匹配QUERY_STRING:
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]
【讨论】: