0

I'm in the process of moving a Wordpress blog from the root ...com to ...com/blog/

Currently all the posts from 2010 - 2012 start this way .com/2010 - .com/2011 - .com/2012

I'd like to catch only urls that have 2010, 2011 and 2012 following .com and add blog in front.

Example:

www.domain.com/2012/1/post-title/

needs to become

www.domain.com/blog/2012/1/post-title/

I still have wordpress pages in the root and want to make sure they don't redirect too.

Here is the default wordpress htaccess

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

Thanks

1 Answer 1

1

You can use something like

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

The new .htaccess file would be like

RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]

RewriteRule ^2010/(.*) /blog/2010/$1 [L,R=301]
RewriteRule ^2011/(.*) /blog/2011/$1 [L,R=301]
RewriteRule ^2012/(.*) /blog/2012/$1 [L,R=301]

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

I hope above rules are self explanatory. You can optimize above rule in 3 lines can to 1 line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.