.htaccess 重定向问题

发布于 2025-01-06 12:17:40 字数 909 浏览 0 评论 0原文

我在我的域上使用 WordPress。我最初将其安装在子目录中:

www.example.com/wpblog/

我现在已将博客移至我网站的根目录中,并且我已将永久链接结构从 ../2011/03/name-of-post 更改为到../帖子名称。

我正在尝试将所有使用旧 URL 和结构的链接重定向到我的博客。

我使用此代码成功从 /wpblog/ 重定向到网站根目录:

RewriteEngine On
RewriteBase /
Redirect 301 /wpblog/ http://www.example.com/

但现在我需要更改旧的永久链接结构以删除 /2011/03/,留下 www.example.com/name-of-post (来自:www.example.com/wpblog/2011/03/name-of-post)。我添加了这段代码,它 100% 有效:

RedirectMatch 301 /([0-9]+)/([0-9]+)/(.*)$ http://www.example.com/$3

问题是,这也破坏了我的媒体文件的链接 (www.example.com/wp-content/2011/03/name-of-media)。因此,我需要从永久链接重定向中排除 /wp-content/ 目录(但不是 /wpblog/ 重定向)。我因此更改了永久链接重定向:

RewriteCond %{REQUEST_URI} "/wp-content/"
RewriteRule 301 /([0-9]+)/([0-9]+)/(.*)$ http://www.example.com/$3

但这会破坏整个网站,给我一个错误......

如果有人可以帮助我,我将非常感激!我已经为此抓狂了!

I'm using WordPress on my domain. I originally installed it in a sub-directory:

www.example.com/wpblog/

I have now moved the blog into the root of my site AND I have changed the permalink structure from ../2011/03/name-of-post to ../name-of-post.

I am trying to redirect all links to my blog which use the old URL and structure.

I use this code to successfully redirect from /wpblog/ to the site root:

RewriteEngine On
RewriteBase /
Redirect 301 /wpblog/ http://www.example.com/

But now I need to change the OLD permalink structure to remove the /2011/03/, leaving me with www.example.com/name-of-post (from: www.example.com/wpblog/2011/03/name-of-post). I added this code, which works 100%:

RedirectMatch 301 /([0-9]+)/([0-9]+)/(.*)$ http://www.example.com/$3

The trouble is, that also breaks links to my media files (www.example.com/wp-content/2011/03/name-of-media). I therefore need to exclude the /wp-content/ directory from the permalink redirect (but not the /wpblog/ redirect). I changed the permalink redirect thus:

RewriteCond %{REQUEST_URI} "/wp-content/"
RewriteRule 301 /([0-9]+)/([0-9]+)/(.*)$ http://www.example.com/$3

But this breaks the entire site, giving me an error.....

I'd be really grateful if someone could help me out! I've been tearing my hair out over this!

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

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

发布评论

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

评论(1

沫雨熙 2025-01-13 12:17:40

试试这个:

RewriteEngine on
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteCond %{REQUEST_URI} ^/wp-content/ [NC]
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-l
RewriteRule /(?:[\d]+)/(?:[\d]+)/(.*)$ http://www.grvhi.com/$1 [R=301,L]

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

Try this:

RewriteEngine on
RewriteBase /

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^ - [L]

RewriteCond %{REQUEST_URI} ^/wp-content/ [NC]
RewriteRule %{REQUEST_FILENAME} !-f
RewriteRule %{REQUEST_FILENAME} !-l
RewriteRule /(?:[\d]+)/(?:[\d]+)/(.*)$ http://www.grvhi.com/$1 [R=301,L]

RewriteRule ^index\.php$ - [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文