I have a website using wildcard subdomains.
I need to change the domain and redirect all old pages to the new domain.
For example: I want to redirect this page
x.olddomain.example/stackoverflow
to x.NewDomain.example/stackoverflow
without making any changes on the subdomains folders.
I used this code :
RewriteCond %{HTTP_HOST} ^(.+\.)?olddomain.example$ [NC]
RewriteRule ^ http://%1newdomain.example%{REQUEST_URI} [R=301,L]
But the result is:
x.olddomain.example/stackoverflow
redirectw to
x.olddomain.example/?name=stackoverflow
Please note : that the problem occurs when you try to enter the domain directly to browser .. but if you are on the subdomain it's working fine
If you are browsing the page
x.olddomain.example
and you clicked on this link through that page
x.olddomain.example/stackoverflow
, then
it redirects fine to
x.newdomain.example/stackoverflow
But if you tried to enter x.olddomain.example/stackoverflow
directly through the browser it redirects to x.newdomain.example/?name=stackoverflow