简体   繁体   English

WordPress 中的 URL 重定向 php 或 .htaccess

[英]URL Redirect php or .htaccess in WordPress

I have a wordpress blog, and having issue with URL's.. Few months ago i used link with slug (Forcely changed to blog when i switched to MultiSite) like this, example.com/blog我有一个 wordpress 博客,并且 URL 有问题。几个月前,我使用了带有 slug 的链接(当我切换到 MultiSite 时强制更改为博客), example.com/ blog

Now I am using wordpress without BLOG and removed slug "BLOG" after link.现在我在没有BLOG 的情况下使用 wordpress,并在链接后删除了“BLOG”。

Problem is many quality backlinks i have with old blog slug .问题是我在旧博客 slug 上有很多高质量的反向链接。
When someone visit my blog with example.com/blog/post-permalink it redirects to not_found_404 error because link should be looks like this, example.com/post-permalink .当有人使用example.com/blog/post-permalink访问我的博客时,它会重定向到not_found_404错误,因为链接应该是这样的, example.com/post-permalink

I am confused, how to redirect every request that comes with example.com/blog/post-name and redirect to example.com/post-name我很困惑,如何重定向example.com/blog/post-name附带的每个请求并重定向到example.com/post-name

Redirecting pages below /blog/重定向下面的页面 /blog/

It should be as simple as a .htaccess in your domain root directory (where index.php lives) with the following contents:它应该像域根目录(index.php 所在的位置)中的 .htaccess 一样简单,其中包含以下内容:

RewriteEngine on
RewriteRule ^blog/(.*)$ /$1 [L,R=301]

Note that RewriteEngine on is required only once per .htaccess file, so skip this if it is present already.请注意,每个 .htaccess 文件只需要RewriteEngine on一次RewriteEngine on ,所以如果它已经存在,请跳过它。

The RewriteRule itself matches all URL beginning ( ^ ) with blog/ and catches everything following until the end ( $ ). RewriteRule本身匹配所有以blog/开头的 URL ( ^ ) 并捕获后面的所有内容,直到结尾 ( $ )。 The caught part is stored in the reference $1 .捕获的部分存储在引用$1

This reference is thereafter used in the redirection target, as /$1 .此引用此后在重定向目标中使用,作为/$1

L means that no further rules in the .htaccess are evaluated. L表示不评估 .htaccess 中的其他规则。

R=301 redirects using a HTTP/1.1 301 Permanent redirect, which is desirable for SEO and redirects all visitors to the new URL. R=301使用 HTTP/1.1 301 永久重定向进行重定向,这对 SEO 来说是可取的,并将所有访问者重定向到新 URL。

Redirecting /blog itself重定向/博客本身

In addition to the above insert除了上面的插入

RewriteRule ^blog(/?)$ / [L,R=301]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM