【问题标题】:How to redirect multiple similar URLs with one query?如何通过一个查询重定向多个相似的 URL?
【发布时间】:2012-11-15 22:24:58
【问题描述】:

我目前有很多这样的网址:

http://www.domain.com/classes-dallas-tx.html

我需要将所有 URL 更改为以下内容:

http://www.domain.com/classes-in-dallas-tx.html

我只需要将“in”添加到现在没有它的每个 URL 中。

我可以为 .htaccess 文件使用一个查询来为我处理所有 URL 吗?我打算使用 301 重定向。

谢谢!

【问题讨论】:

标签: html .htaccess url redirect


【解决方案1】:

试试:

RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3.html

或者

RewriteEngine On
RewriteRule ^/?([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3.html [L,R=301]

在文档根目录的 htaccess 文件中。

【讨论】:

  • 太棒了!第一个成功了!就 Google 和 SEO 而言,两者之间是否存在偏好?
  • @user1858780 一个使用 mod_alias(第一个),另一个使用 mod_rewrite。据 Google 所知,没有区别,但如果您同时使用来自两个模块的指令,指令可能会相互干扰。
  • 大家好,看来此代码已停止为我工作。很长一段时间都很好,现在它导致错误。我有这个代码:'code' RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-in-$2-$3。 html RedirectMatch 301 ^/([^-]+)-([^-]+)-([^-]+)-([^-]{2})\.html$ /$1-$2-in-$3 -$4.html 'code' URL Switch 我想要:domain.com/music-classes-dallas-tx.html 到 domain.com/music-classes-in-dallas-tx.html
猜你喜欢
  • 2021-04-02
  • 2010-10-26
  • 1970-01-01
  • 2015-11-23
  • 2016-06-11
  • 1970-01-01
  • 1970-01-01
  • 2018-08-19
  • 1970-01-01
相关资源
最近更新 更多