I have recently change some URLs from my website to make it more SEO friendly. I have old urls that I would like to link to new urls. The old urls are no longer available but I would like the old urls to redirect to the new urls.
My current 301 redirect code below is for http:// to https://www, which I need.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mywebsite.com [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [L,R=301,NC]
How do I make it so that I can also redirect from old urls to new urls as well. Is it possible with the 301 redirect?
Old url examples:
www.mywebsite.com/book-stories.html
www.mywebsite.com/book-journals.html
New url examples:
www.mywebsite.com/stories.html
www.mywebsite.com/journals.html
Any help would be much appreciated.
2
Answers
I tried the above code and didn't work and to be honest I could have been doing it incorrectly. I did look into it further and tried another 301 redirect
That worked for me. Hope this helps anyone else who will encounter this issue.
If you only have a handful, static redirections you can do it appending
RewriteRules
just as you are doing:If they all have a fixed pattern, you could exploit that to reduce the amount of rules.
If you have many different rules that you will be updating, you can look into indexed maps or even database-based RewriteMaps