Redirect with HTTP_HOST redirects to sub subdomain

Redirect with HTTP_HOST redirects to sub subdomain - If a page has internal and external outgoing links to redirecting URLs, it’s returning 3xx (301, 302, etc.) HTTP status codes standing for redirection. This issue means that the page does not exist on a permanent or temporary basis. It appears on most of the popular web browsers, usually caused by a misconfigured website. However, there are some steps you can take to ensure the issue isn’t on your side. You can find more details about redirecting URLs by reading the Google Search Central overview. In this article, we’ll go over how you can fix the Redirect with HTTP_HOST redirects to sub subdomain error on your web browser. Problem :


The settings



I have the following .htaccess rule



RewriteCond %HTTP_HOST !^www.
RewriteCond %HTTP_HOST !^de.
RewriteRule ^(.*)$ http://www.%HTTP_HOST/$1 [R=301,L]


This works great to redirect any subdomain that is not valid (www or de) to the www subdomain.



I have seen solution, but they only depend on single domain sites.



I have multiple domains:



http://www.example.com
http://www.example.net
http://de.example.com


which all serve their own brand of site.



Now I have the .htaccess rule that is mentioned above and it works beautifully if someone types in http://example.com it redirects to http://www.example.com.



The problem



If someone types in http://test.example.com, it redirects to http://www.test.example.com and if someone types in http://test.example.net, it redirects to http://www.test.example.net.



The question



How can I make it so that it redirects http://test.example.com to http://www.example.com? And http://test.example.net to http://www.example.net.



I need an domain insensitve solution because more domains will be added in the future.


Solution :

To redirect using the sub-domain as a parameter:




# HTTP 301 Redirect test.*.net -> www.*.net

RewriteCond %HTTP_HOST ^test.([^.]+).net$ [NC]

RewriteRule (.*) http://www.%1.net/$1 [R=301,L)



# HTTP 301 Redirect test.*.com -> www.*.com

RewriteCond %HTTP_HOST ^test.([^.]+).com$ [NC]

RewriteRule (.*) http://www.%1.com/$1 [R=301,L)




If you also want to redirect when there's no subdomain (e.g. http://example.com) to the main website using the www. subdomain (http://www.example.com):




# HTTP 301 Redirect *.net -> www.*.net

RewriteCond %HTTP_HOST ^([^.]+).net$ [NC]

RewriteRule (.*) http://www.%1.net/$1 [R=301,L)



# HTTP 301 Redirect *.net -> www.*.net

RewriteCond %HTTP_HOST ^([^.]+).com$ [NC]

RewriteRule (.*) http://www.%1.com/$1 [R=301,L)




If you're trying to achieve a lot with your .htaccess files you may find it helps to test your conditions and how they affect URL rewriting on the htaccess Made-With-Love website.



In case this is where you struggled, it is always worth remembering that in .htaccess, parameters prefixed with percent symbols (e.g. %1) reference values from the last matched RewriteCond expression, normally values that have been marked as being of interest by being surrounded in brackets (), and parameters prefixed with dollar symbols (e.g. $1) reference values in the RewriteRule expression, normally values that are automatically assigned by Apache and relating to the URL.


We hope that this article has helped you resolve the htaccess, redirects, subdomain error in your web browsers. Enjoy browsing the internet uninterrupted!

Comments

Popular posts from this blog

How to redirect to any domain [duplicate]

"302 found" for index page bad for SEO?

Create redirect from url like www.example.us/?p=100&option=