.htaccess 301 重定向部分网址

发布于 2024-12-13 06:51:29 字数 788 浏览 0 评论 0原文

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

为了进行永久重定向,我使用以下代码(.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

I am redesigning my website and in the process restructuring some of the linking structure.

To do the permanent redirects I am using the following code (.htaccess)

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

I am using a CMS and changing the link for a category changes the path of the url like so:

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

to

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

How should I code (.htaccess) the redirect of any URL that has

thedomain.com/old-category-link

(i.e

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

)

to

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

Thank you

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安穩 2024-12-20 06:51:29

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

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. <一href="http://thedomain.com/old-category-link/article50.html" rel="noreferrer">http://thedomain.com/old-category-link/article50.html 他们会重定向到 http://thedomain.com/new-category-link/article50.html< /a>

Not exactly sure what you are asking to be redirected to, but is it something like this?

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

This will make is so if someone requests:

  1. http://thedomain.com/old-category-link they will get redirected to http://thedomain.com/new-category-link
  2. http://thedomain.com/old-category-link/ they will get redirected to http://thedomain.com/new-category-link/
  3. http://thedomain.com/old-category-link/article1.html they will get redirected to http://thedomain.com/new-category-link/article1.html
  4. http://thedomain.com/old-category-link/article50.html they will get redirected to http://thedomain.com/new-category-link/article50.html
或十年 2024-12-20 06:51:29

没有答案对我有用。这是我的 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

No answer worked for me. Here is what is working with my Wordpress site.

Example:

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

So, I want to replace /xxx/yyy/ with the normal /wp-content/ path of WordPress.

Put this in your .htaccess file.

RewriteEngine on
RedirectMatch 301 /xxx/yyy/(.*) http://website.com/wp-content/$1
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文