Old domain name hosted base live: www.olddomain/sub/directories/to/live/web/dir/
I need only the domain name changed to new domain, and paths information deleted, just leaving the browser window to load:
"www.thenewdomain"
The "old" domain is using a "Shared IP", and "old" domain's mapping is where the extra paths come from.
Resulting in www.thenewdomain/sub/directories/to/live/web/dir/
It must also work over http & https.
This code below leaves the path, but path can't be used on new domain, just domain.TLD, with or without www.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain$
RewriteRule ^(.*)$ $1 [R=301,L]
Where's the issue? Thank you.
Old domain name hosted base live: www.olddomain/sub/directories/to/live/web/dir/
I need only the domain name changed to new domain, and paths information deleted, just leaving the browser window to load:
"www.thenewdomain"
The "old" domain is using a "Shared IP", and "old" domain's mapping is where the extra paths come from.
Resulting in www.thenewdomain/sub/directories/to/live/web/dir/
It must also work over http & https.
This code below leaves the path, but path can't be used on new domain, just domain.TLD, with or without www.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.olddomain$ [OR]
RewriteCond %{HTTP_HOST} ^olddomain$
RewriteRule ^(.*)$ http://www.thenewdomain$1 [R=301,L]
Where's the issue? Thank you.
Share Improve this question edited Mar 2 at 21:35 P D asked Mar 2 at 21:08 P DP D 11 bronze badge 2- Where are these directives being used? By the nature of the rule you've posted I assume you are using this directly in the server (or virtualhost) config? (The current answer is assuming you are using this in a directory or .htaccess context.) – MrWhite Commented Mar 2 at 22:59
- By "Shared IP" do you mean "Shared Hosting"? Simply having a "Shared IP" makes no difference here. However, if you are on a "Shared Host" then you probably don't have access to the server config (but then the rule you've posted wouldn't be "working" in the way you describe?) – MrWhite Commented Mar 2 at 23:09
1 Answer
Reset to default 0I guess you can try this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\$ [NC]
RewriteRule ^$ https://www.thenewdomain/ [R=301,L]
RewriteRule ^(.*)$ https://www.thenewdomain/ [R=301,L]