【问题标题】:RewriteRule for URL News IDURL 新闻 ID 的 RewriteRule
【发布时间】:2011-10-01 21:48:18
【问题描述】:

我有点卡住 RewriteRule 301,从旧新闻 ID 更改为新新闻 ID

这是我尝试过的:

RewriteRule ^/news/0(.*)$ /news/$1 [L,R=301]

假设新闻 URL 看起来像他的:

http://www.mydomain.com/news/01/title-of-the-new
http://www.mydomain.com/news/09/title-of-the-new
http://www.mydomain.com/news/012/title-of-the-new
http://www.mydomain.com/news/032/title-of-the-new

我想改成:

http://www.mydomain.com/news/1/title-of-the-new
http://www.mydomain.com/news/9/title-of-the-new
http://www.mydomain.com/news/12/title-of-the-new
http://www.mydomain.com/news/32/title-of-the-new

【问题讨论】:

  • 看起来应该可以,你得到了什么样的结果?
  • Ross,它不会从 01 重定向到 1(示例)。
  • 这可能是由于另一个规则 - 我刚刚测试了这个,http://localhost/news/01/hello 重定向到 http://localhost/news/1/hello
  • 我设法修复了它。将RewriteRule ^/news/0(.*)$ /news/$1 [L,R=301] 替换为RewriteRule ^news/0(.*)$ /news/$1 [L,R=301]
  • 很高兴您修复了它,请将其发布为答案 :)

标签: apache .htaccess url mod-rewrite seo


【解决方案1】:

我设法修复它替换

RewriteRule ^/news/0(.*)$ /news/$1 [L,R=301] 

RewriteRule ^news/0(.*)$ /news/$1 [L,R=301]

【讨论】:

    【解决方案2】:

    你为什么需要它?您的规则应该可以解决问题,但不是您需要的(我认为)。当您打开 http://www.mydomain.com/news/01/title-of-the-new 时,它会运行带有 URL http://www.mydomain.com/news/1/title-of-the-new 的服务器端脚本

    【讨论】:

    • 我为什么需要它?因为我正在重新设计网站.. 目前所有的新闻 ID 都是从 0 开始的(例如:01、02、032、055 等)。我从一开始就使用服务器端脚本来添加零。所以我决定删除 0 并更新 htaccess 文件中的 SEO?
    【解决方案3】:

    我认为删除所有前零的更强大的规则会更好一些:

    重写规则 ^news/0+(.*)$ /news/$1 [L,R=301]

    【讨论】:

      猜你喜欢
      • 2017-01-12
      • 1970-01-01
      • 2016-07-22
      • 1970-01-01
      • 2020-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多