【问题标题】:htaccess: rewrite and redirect 301htaccess:重写和重定向 301
【发布时间】:2016-11-18 09:36:23
【问题描述】:

我用.htaccess重写了这个模式下查询字符串生成的一个动态url类别:

RewriteEngine On
RewriteRule ^id1-([^-]*)-id2-([^-]*)$ /page.php?id1=$1&id=$2 [L]

现在我的重写工作正常,例如,以下 url 驱动到同一页面:

http://www.mysite.it/id1-01234-id2-56789
http://www.mysite.it/page.php?id1=01234&id2=56789

但现在我想要一个重定向 301,从第二种类型到第一种类型,用于所有动态 url。例如:

来自

http://www.mysite.it/page.php?id1=01234&id2=56789 

http://www.mysite.it/id1-01234-id2-56789

下面的方法不行:

RewriteEngine On
RewriteRule ^id1-([^-]*)-id2-([^-]*)$ /page.php?id1=$1&id=$2 [L]
RewriteCond %{QUERY_STRING} (^|&)id1=$1($|&)
RewriteCond %{QUERY_STRING} (^|&)id2=$2($|&)
RewriteRule ^page\.php$ /id1-id2? [L,R=301]

哪里出错了?

你能帮帮我吗?

【问题讨论】:

  • ID 总是只有数字?

标签: apache .htaccess


【解决方案1】:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/page.php
RewriteCond %{THE_REQUEST} \?id1=(\w+)&id2=(\w+)\s
RewriteRule ^page.php /id1-%1-id2-%2? [NC,R=301,L]

RewriteRule ^id1-([^-]*)-id2-([^-]*)$ /page.php?id1=$1&id2=$2 [L]

【讨论】:

    猜你喜欢
    • 2016-09-28
    • 2013-01-27
    • 2013-12-21
    • 2015-03-04
    • 2011-11-19
    • 2023-03-25
    • 2015-08-08
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多