【问题标题】:Rewrite URL SEO重写 URL SEO
【发布时间】:2013-04-18 15:23:52
【问题描述】:

我的网站有这样的网址

http://www.mydomain.com/index.php?page=doctors&docid=99

使用 SEO 重写

RewriteRule ^doctors/([0-9]+)/(.*).html$ index.php?page=doctors&docid=$1 [L]

我明白了

www.mydomain.com/doctors/13/Dr.-John-Smith.html

但我想要一个像这样更友好的网址

www.mydomain.com/Dr.-John-Smith.html

我怎样才能获得这个网址。

【问题讨论】:

标签: apache .htaccess url mod-rewrite seo


【解决方案1】:

重写查询字符串

如果您受雇从头开始重建现有网站,您可能会使用 URL 重写将旧网站上的 20 个最受欢迎的 URL 重定向到新网站上的位置。这可能涉及将 prod.php?id=20 之类的内容重定向到 products/great-product/2342,它本身会被重定向到实际的产品页面。

Apache 的 RewriteRule 仅适用于 URL 中的路径,不适用于 id=20 等参数。要进行这种类型的重写,您需要参考 Apache 环境变量 %{QUERY_STRING}。这可以像这样完成:

RewriteEngine On
RewriteCond   %{QUERY_STRING}           ^id=20$                   
RewriteRule   ^prod.php$             ^products/great-product/2342$      [L,R=301]
RewriteRule   ^products/(.*)/([0-9]+)$  ^productview.php?id=$1             [L]

在此示例中,第一个 RewriteRule 触发从旧网站的 URL 到新网站的 URL 的永久重定向。第二条规则将新 URL 重写为显示产品的实际 PHP 页面。

我希望这会有所帮助,请在此处了解有关重写的更多信息: http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/

它的布局非常简单。希望对您有所帮助,如果您有任何其他问题,请告诉我。谢谢。

【讨论】:

  • 好的,但是如果 url 是 www.mydomain.com/doctors/13/Dr.-John-Smith.html 转换成 www.mydomain.com/Dr.John-Smith.html 什么我需要做
猜你喜欢
  • 2012-07-17
  • 2011-11-27
  • 1970-01-01
  • 2011-06-17
  • 1970-01-01
  • 1970-01-01
  • 2014-11-11
  • 2016-01-21
  • 1970-01-01
相关资源
最近更新 更多