【问题标题】:.htaccess 301 redirects for part of url.htaccess 301 重定向部分 url
【发布时间】:2011-11-02 21:37:59
【问题描述】:

我正在重新设计我的网站,并在此过程中重组一些链接结构。

要进行永久重定向,我使用以下代码 (.htaccess)

RedirectMatch permanent old-link($|\.html) http://thedomain.com/new-link.url

我正在使用 CMS 并更改类别的链接会更改 url 的路径,如下所示:

thedomain.com/old-category-link/old-article-url.html

thedomain.com/new-category-link/old-article-url.html

我应该如何编码 (.htaccess) 任何具有

的 URL 的重定向
thedomain.com/old-category-link

(即

thedomain.com/old-category-link/old-article.html
thedomain.com/old-category-link/old-article-2.html
thedomain.com/old-category-link/old-article-999.html

)

thedomain.com/new-category-link/any-articles-old-url.html

谢谢

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    不完全确定您要求重定向到什么,但它是这样的吗?

    RedirectMatch permanent old-category-link(.*) http://thedomain.com/new-category-link$1
    

    如果有人要求,这将是这样:

    1. http://thedomain.com/old-category-link 他们将被重定向到 http://thedomain.com/new-category-link
    2. http://thedomain.com/old-category-link/ 他们将被重定向到http://thedomain.com/new-category-link/
    3. http://thedomain.com/old-category-link/article1.html 他们将被重定向到 http://thedomain.com/new-category-link/article1.html
    4. http://thedomain.com/old-category-link/article50.html 他们将被重定向到 http://thedomain.com/new-category-link/article50.html

    【讨论】:

    • 是的,你明白我的问题。是的,你的回应有效。谢谢。
    【解决方案2】:

    没有答案对我有用。这是我的 Wordpress 网站的工作原理。

    例子:

    OLD URL: http://website.com/xxx/yyy/picture.png
    NEW URL: http://website.com/wp-content/picture.png
    

    所以,我想将 /xxx/yyy/ 替换为 WordPress 的普通 /wp-content/ 路径。

    把它放在你的 .htaccess 文件中。

    RewriteEngine on
    RedirectMatch 301 /xxx/yyy/(.*) http://website.com/wp-content/$1
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-12-21
      • 2015-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-28
      相关资源
      最近更新 更多