【问题标题】:.htaccess redirect, change GET variables.htaccess 重定向,更改 GET 变量
【发布时间】: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


    【解决方案1】:

    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]
    

    【讨论】:

      猜你喜欢
      • 2013-09-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-10-26
      • 2011-04-02
      • 1970-01-01
      • 1970-01-01
      • 2011-12-02
      相关资源
      最近更新 更多