1
votes

I'm trying to redirect all existing urls to a new slightly simplified url structure, and wish to keep the existing links that have been indexed on google/bing intact.

The current url for posts looks like this /blog/post/some-random-post-here the new post url's are virtually the same but no longer have /post/ in them. Instead its /blog/some-random-post-here

I have created a new htaccess rule for the new urls. So as of now both versions of the url's work. However I wish to keep one copy for SEO reasons. This is on a blog made from scratch (this is not WordPress or other blogging softwares)

Here are the rewrite rules in my htaccess for old and new urls.

**OLD URL:** RewriteRule ^post/([^/]+)/$ index.php?controller=post&action=view&post=$1 [L]

 ------------------------------------------------------------------------

**NEW URL:** RewriteRule ^([^/]+)/$ index.php?controller=post&action=view&post=$1 [L]

What would I need to add to the OLD URL structure in order to make a 301 permanent redirect to the new url structure? Both the OLD and the NEW rewrite rules are still active. But I rather 301 the old rule to the new URL.

Thank you in advance.

1

1 Answers

0
votes

You can use RedirectMatch directive for this url redirection, it's easy.

Try :

RedirectMatch 301 ^/blog/post/(.*)$ http://domain.com/blog/$1

Or Try mod_rewrite To remove query strings

 RewriteEngine on


RewriteRule ^blog/post/(.*)$ http://example.com/blog/$1? [NC,R,L]

Empty question mark ? at the end is important as it will discard the original query string from url.

will 301 redirect

http://example.com/blog/post/foo

to

http://example.com/blog/foo