最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Apache mod Rewrite need to change domain name only, while removing paths from old domain - Stack Overflow

programmeradmin0浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

I 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]

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论