Suresh
Suresh

Reputation: 3

301 Redirection of url Pattern in htaccess

Previously I have vbulletin forum installed on main domain. Now I have replaced it with WP blog and shifted forum to subfolder. Both WP and vB has seperate htaccess files. Please help me to redirect old forum urls to new ones.

Old url pattern:

www.domain.com/f1/post-title/
www.domain.com/f2/post-title/
www.domain.com/f3/post-title/

New url pattern:

www.domain.com/forums/f1/post-title/
www.domain.com/forums/f2/post-title/
www.domain.com/forums/f3/post-title/

Please somebody help me with rewriting rules for correct redirection. Also mention which htaccess (WP or vB) to put the code. Thanks in advance.

Upvotes: 0

Views: 1802

Answers (1)

Prix
Prix

Reputation: 19528

It needs to be placed on the .htaccess on the root folder of your domain.

So if your root folder is /home/youraccount/public_html/ then in the .htaccess in that folder.

This will redirect as you asked above, any forum/topic to forums/forum/topic

Options +FollowSymLinks -MultiViews

RewriteEngine on
RewriteBase /

RewriteRule ^(f\d+)/([^/]+)/?$ /forums/$1/$2/ [R=301,L]

I could use ([^/]+) twice but since you mentioned you have a WordPress in the root now then you should need a more specific rule for the first folder like the above.

This will match the forum id aka f1, f2 ... up to any amount of numbers:

(f\d+)

This will get anything not a / so it will get the post id and title altogether.

([^/]+)

If you have more rules inside your .htaccess file make sure you place this rule after RewriteEngine on and before any other rule, so it doesn't conflict with other rules and redirect as you asked:

RewriteRule ^(f\d+)/([^/]+)/?$ /forums/$1/$2/ [R=301,L]

Upvotes: 0

Related Questions