: .htaccess rewrite but keep basic URL I have basic domain, for example, domain1.com. Also I have domain2.com which is addon domain, and I want to redirect domain2.com to domain.com?parameter=value,
I have basic domain, for example, domain1.com. Also I have domain2.com which is addon domain, and I want to redirect domain2.com to domain.com?parameter=value, which is basically domain1.com, but with another template, but that path in URL stays same, domain2.com, not domain1.com. .htaccess file is created inside addon domain directory (public_html/domain2.com), and I have these two lines:
RewriteCond % ^domain2.com
RewriteRule ^(.*) domain1.com?parameter=value [P]
Rewrite works, but URL in browser changes to domain1.com.
EDIT: U have this code to .htaccess, but URL change to domain1.com, instead to stay on domain2.com.
RewriteCond %{HTTP_HOST} ^domain2.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain2.com$
RewriteRule ^/?$ "http://domain1.com/?parameter=value" [R=301,L]
More posts by @Fox8124981
2 Comments
Sorted by latest first Latest Oldest Best
Unless I'm mistaken, this should be along the lines what you're looking for:
RewriteEngine On
Options +FollowSyminks
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ my-new-domain.com/ [NC,L]
If you're wanting to keep the URL the same, there's no need for a R=302 flag, as it pushes the browser to redirect with a 302 code. Essentially what you're wanting to do is just mask the URL to the proper location.
(Credit to @closetnoc for providing what kicked my train of thought)
Try this:
RewriteCond %{HTTP_HOST} ^mydomain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.mydomain.com$ [NC]
RewriteRule ^(.*)$ my-new-domain.com/ [R=301,L]
Your RewriteRule from your question is fundamentally incorrect:
RewriteRule ^/?$ "http://domain1.com/?parameter=value" [R=301,L]
My example is a typical blanket redirect that will take the request and parameters from the old domain and forward to the new domain.
In your case the domain1.com/?parameter=value does not need to be escaped (using back-slashes) or quoted. The ^(.*)$ my-new-domain.com/ in my example will take the value from (.*) which would be the URI consisting of the directory path, file, and any parameters and place it at the end of a new request with your new domain using .
So any request for old-domain.com/eagle-brand/products.php?type=food will become new-domain.com/eagle-brand/products.php?type=food.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.