【问题标题】:htaccess 301 redirect for non friendly urlshtaccess 301 重定向非友好网址
【发布时间】:2017-08-03 07:42:10
【问题描述】:

我很难找到解决这个问题的方法。 我的 htaccess 中有一个重写规则,当我直接访问它时会重写 url:

RewriteRule [a-zA-Z0-9_]+-c([0-9]+)-p([0-9]+)$   list.php?id=$1&page=$2   [QSA]

所以www.domain.com/list-of-products-c1-p1 工作正常。

但我不想要的www.domain.com/list.php?id=1&page=1 也是如此!

有什么方法可以 301 将这个不友好的 url 重定向到使用 htaccess 的 seo 友好的 url?

谢谢!

【问题讨论】:

  • 我没有得到相关的答案,所以我决定使用 PHP 函数并在页面 function redirect301pages($page) { $mystring = curPageURL(); if ($page=='list.php') { $unf = strpos($mystring, $page); if (isset($unf) && !empty($unf)) { if (isset($_GET['page'])) $page=$_GET['page']; else $page=1; if (isset($_GET['id'])) { #$link=get your link here header("HTTP/1.1 301 Moved Permanently"); header("Location: ".$link.""); } } } //list.php } 时在顶部调用它

标签: .htaccess url redirect


【解决方案1】:

试试下面的规则,

RewriteCond %{REQUEST_FILENAME}\.php -f [OR]
RewriteCond %{QUERY_STRING} ^id=([\d]+)&page=([\d]+)$
RewriteRule ^ list-of-products-c%1-p%2 [R=301,L]

【讨论】:

  • "list-of-products" 它的动态基于 id。所以它可以是 id=1 的苹果列表或 id=2 的图书列表
猜你喜欢
  • 2013-01-06
  • 2020-02-09
  • 1970-01-01
  • 2010-12-03
  • 2012-11-25
  • 1970-01-01
  • 1970-01-01
  • 2014-02-24
  • 1970-01-01
相关资源
最近更新 更多