2

很简单的问题。我需要更改网址

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

其中 [x] 是任意数字

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

只需使用 .htaccess 301 重定向将 ?page= 更改为 ?id= 。

我怎样才能做到这一点?

4

1 回答 1

2

匹配QUERY_STRING里面的 a RewriteCond

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]
于 2012-10-22T15:27:36.637 回答