Htaccess 301使用通配符重定向到单独的部分

时间:2021-05-29 11:18:38

I'm trying to redirect past incoming links to new sections because a client has renovated there site.

我正在尝试将传入的链接重定向到新的部分,因为客户端已经在那里进行了翻新。

e.g.

 http://www.asite.co.uk/news540.html 

to

 http://www.asite.co.uk/category/news

also

 http://www.asite.co.uk/topichome.html 

to

 http://www.asite.co.uk/topic-homepage/

In the first example I want to catch any incoming links that contain news prior to the html with the number being a wild card. In the second one I want to catch specific topics and redirect them to the new topic homepage.

在第一个例子中,我希望捕获任何包含html之前的新闻的传入链接,其中的数字是外卡。在第二个中,我想捕获特定主题并将它们重定向到新主题主页。

Thank in advance

预先感谢

1 个解决方案

#1


For your first scenario, something like this should do the trick:

对于你的第一个场景,像这样的东西应该做的伎俩:

RewriteRule ^news([0-9]+)\.html$ http://www.asite.co.uk/category/news [R=301,L]

This rule will "catch" any newsXXXX.html and redirect it (301) to /category/news (where XXXX is any number).

此规则将“捕获”任何newsXXXX.html并将其(301)重定向到/ category / news(其中XXXX是任意数字)。

For the second scenario:

对于第二种情况:

RewriteRule ^topichome.html$ http://www.asite.co.uk/topic-homepage/ [R=301,L]

This is much simpler. pageA.html is redirected to pageb.html.

这更简单。 pageA.html被重定向到pageb.html。

Note that in both rules:
left url is the original one, from root
right url is the "final, redirected" one

请注意,在两个规则中:left url是原始url,从root权限url是“final,redirected”

#1


For your first scenario, something like this should do the trick:

对于你的第一个场景,像这样的东西应该做的伎俩:

RewriteRule ^news([0-9]+)\.html$ http://www.asite.co.uk/category/news [R=301,L]

This rule will "catch" any newsXXXX.html and redirect it (301) to /category/news (where XXXX is any number).

此规则将“捕获”任何newsXXXX.html并将其(301)重定向到/ category / news(其中XXXX是任意数字)。

For the second scenario:

对于第二种情况:

RewriteRule ^topichome.html$ http://www.asite.co.uk/topic-homepage/ [R=301,L]

This is much simpler. pageA.html is redirected to pageb.html.

这更简单。 pageA.html被重定向到pageb.html。

Note that in both rules:
left url is the original one, from root
right url is the "final, redirected" one

请注意,在两个规则中:left url是原始url,从root权限url是“final,redirected”