简体   繁体   中英

Regex to redirect 301 a folder and all posts from that folder in Wordpress

Just moved my website from www.example.com/blog to www.example.com .

I need to add a 301 redirect to my .htaccess to redirect everything that is called with the www.example.com/blog/... url, like a www.example.com/blog/category to www.example.com/category or www.example.com/blog/post-title to www.example.com/post-title .

I've redirected the folder but it doesn't seem to work. Can you help me?

This is the code with the 301 of the folder:

RewriteEngine On
RewriteRule ^blog(/.*)?$ /$1 [L,NC,NE,R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-
RewriteRule ^blog(/.*)?$ /$1 [L,NC,NE,R=301]
RewriteRule ^index\.php$ - [L]
RewriteRule . /index.php [L]

Inside your site root .htaccess have this rule at the top:

RewriteEngine On

RewriteRule ^blog(/.*)?$ https://%{HTTP_HOST}/$1 [L,NC,NE,R=301]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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