简体   繁体   English

301 永久链接重定向 htaccess

[英]301 permalink redirect htaccess

I've searched to no avail, hoping that someone can be my hero.我搜索无果,希望有人能成为我的英雄。 I have 2 things going on.我有两件事要做。

I recently moved wordpress to the root folder and currently have the following redirect in my htaccess and all is working properly.我最近将 wordpress 移动到根文件夹,目前在我的 htaccess 中有以下重定向,并且一切正常。

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.website.com
RewriteRule ^blog/(.*)$ http://www.website.com/$1 [L,R=301]

#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

However, I have also changed my blog permalinks from /archives/post-id to /YY/MM/post-name.但是,我也将我的博客永久链接从 /archives/post-id 更改为 /YY/MM/post-name。 How can I implement the permalink redirect so I don't have to redirect each individual blog post?如何实现永久链接重定向,以便我不必重定向每个单独的博客文章? I have tried numerous different things with no luck.我尝试了许多不同的事情,但没有运气。 Also, where in particular should I paste the code in my file (above? below?) so as to not interfere and still work with the initial subdirectory to root redirect?另外,我应该将代码粘贴到我的文件中的什么位置(上面?下面?),以免干扰并仍然使用初始子目录进行 root 重定向? Thank you.谢谢你。

In case someone ever wants to do something similar, I was able to make a slight modification and found something that worked for me.如果有人想做类似的事情,我可以稍作修改并找到对我有用的东西。

I decided to change the permalinks from archives/post-id to archives/post-id/post-name.我决定将永久链接从 archives/post-id 更改为 archives/post-id/post-name。

To accomplish this I added the following code to my htaccess file above my #BEGIN Wordpress area...为此,我将以下代码添加到#BEGIN Wordpress 区域上方的 htaccess 文件中...

# Redirect permalink archive/post-id to archive/post-id/post-name structure.
RedirectMatch 301 ^/archives/(\d+)$ http://www.website.com/archives/?p=$1

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

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