I am releasing an updated version of one of my websites soon on a new domain name and I was wondering how I can make it so that the old urls point to my new website as it has quite a lot of valuable backlinks.
I have read about how to make it 301 redirect in .htaccess but I need something a bit more advanced as some of my url structures have changed. See the examples below.
olddomain.com
newdomain.com
- These will do just fine with the 301 redirect
olddomain.com/author/username
newdomain.com/user/username
- Different URL structure but I want the old urls to redirect towards the new url
olddomain.com/add
newdomain.com/submit
- Different page name for the same functionaly, would like to have these redirect correctly as well
I have no clue how to go about creating these last two redirects so if anyone could point me into the right direction that would be great! :)
Put this code in your DOCUMENT_ROOT/.htaccess
file:
RewriteEngine On
RewriteCond %{HTTP_HOST} olddomain\.com [NC]
RewriteRule ^$ http://newdomain.com/ [R=301,L]
RewriteCond %{HTTP_HOST} olddomain\.com [NC]
RewriteRule ^author/([^/]+)/?$ http://newdomain.com/user/$1 [R=301,L]
RewriteCond %{HTTP_HOST} olddomain\.com [NC]
RewriteRule ^add/?$ http://newdomain.com/submit [R=301,L]
Have you tried using RedirectMatch
?
In the htaccess file in your olddomain.com
document root (it must be different from your newdomain.com
root):
RedirectMatch 301 ^/author/(.*)$ http://newdomain.com/user/$1
RedirectMatch 301 ^/add(.*)$ http://newdomain.com/submit$1
Redirect 301 / http://newdomain.com/
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.