简体   繁体   中英

Redirect all pages from old domain to new specific URL without trailing slash content

I've got an old domain, let's say oldomain.com where I need to redirect all traffic to a specific URL, newdomain.com/path

While redirects from oldomain.com go perfectly, anything with content after the trailing slash will be copied over in the newdomain url structure causing 404's.

For example visiting: oldomain.com/somepage will result in newdomain.com/pathsomepage

What I'm looking for are some rewrite rules that will redirect any and all traffic from oldomain.com to newdomain.com/path without changing the specific "newdomain.com/path" URL.

I'm currently using the rules bellow which leads to the result above:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^oldomain.com
RewriteRule ^(.*) https://newdomain.com/path [P]

PS: the redirect is going to a Magento store.

You are trying to reverse-proxy in your directives (the P flag in the rewrite), but since you are describing a redirect... In the old virtualhost you just need to add a simple Redirect directive like this:

Redirect / https://newdomain.example.com/

This will Redirect all requests no matter how they are made to the new domain. Example GET /something will be redirected to https://newdomain.example.com/something

If you want the target to be a fixed destination like https://newdomain.example.com/path no matter what, use RedirectMatch instead:

RedirectMatch ^ https://newdomain.example.com/path

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM