【问题标题】:redirect old query URL to new rewritten URL .htaccess将旧查询 URL 重定向到新的重写 URL .htaccess
【发布时间】:2013-05-07 01:41:15
【问题描述】:

我已经使用参数成功地清理了我的网址

来自 example.com/index.php?gender=m&height=70&weight=150

进入 example.com/m/70/150/

因此,如果有人输入干净的 URL,他们将获得具有正确参数的页面。

但是,我想这样做,如果有人输入旧网址,它将 301 重定向到新的干净网址

我试过了

RewriteCond %{QUERY_STRING} ^gender=([a-z]+)&height=([0-9-]+)&weight=([0-9-]+)$
RewriteRule ^index\.php$ http://www.example.com/%1/%2/%3? [R=301,L]

但它不起作用,没有错误,没有重写.. URL 看起来还是旧的。

编辑:

当前重写以使 URL 看起来干净

RewriteEngine on

RewriteRule    ^([m]+)en/([0-9-]+)-inches/([0-9-]+)-lbs/?$    index.php?gender=$1&height=$2&weight=$3    [NC,L] 

【问题讨论】:

  • 你的其他规则是什么样的?
  • 好吧,它有点被破解了..但它很实用(请参阅上面的编辑以获取干净版本)我有它,所以 example.com/index.php?gender=m&height=70&weight=150 将变为示例。 com/men/70-inches/150-lbs/ RewriteEngine on RewriteRule ^([m]+)en/([0-9-]+)-inches/([0-9-]+)-lbs/?$ index.php?gender=$1&height=$2&weight=$3 [NC,L]

标签: .htaccess url rewrite


【解决方案1】:

您可能应该检查实际请求而不是 URI/查询字符串,因为这两者都会被其他规则修改。重定向中还缺少一些东西,en-inches-lbs 是看起来更简洁的 URI 的一部分。

试试:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?gender=([a-z]+)&height=([0-9-]+)&weight=([0-9-]+)
RewriteRule ^index\.php$ /%1en/%2-inches/%3-lbs/? [L,R=301]

【讨论】:

  • 正是我需要的。谢谢!
猜你喜欢
  • 1970-01-01
  • 2015-09-14
  • 2022-06-11
  • 2012-11-01
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 2017-09-25
相关资源
最近更新 更多