chetwyn Posted November 4, 2012 Share Posted November 4, 2012 Hi Everyone. We have 2 domains. 1. iconhomeware.com 2. iconhomeware.com.au We would like all requests to be 301 redirect to www.iconhomeware.com.au So far we've been able to figure out how to redirect iconhomeware.com.au to www.iconhomeware.com.au but for the life of us we cannot figure out how to do the other redirects. How to: direct www.iconhomeware.com to www.iconhomeware.com.au and direct iconhomeware.com to www.iconhomeware.com.au This is what we currently have which redirect iconhomeware.com.au to www.iconhomeware.com.au rewritecond %{https} =off RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} iconhomeware\.com\.au [nc] rewriterule ^(.*)$ http://www.iconhomeware.com.au/ [r=301,nc] rewritecond %{https} =on RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} ^iconhomeware\.com\.au [nc] rewriterule ^(.*)$ https://www.iconhomeware\.com\.au/$1 [r=301,nc] Could someone please help.. we are SO stuck Link to comment Share on other sites More sharing options...
Muad'Dib Posted November 4, 2012 Share Posted November 4, 2012 (edited) Hello chetwyn, # Rewrite domains to main one RewriteCond %{HTTP_HOST} ^iconhomeware.(com|com.au) [NC,OR] RewriteCond %{HTTP_HOST} ^www.iconhomeware.com [NC] RewriteRule ^(.*)$ http://www.iconhomeware.com.au/$1 [R=301] Please Note that you can add as many domains as you want in the two RewriteCond. Please also note that to prevent the redirection from looping, you SHALL NOT put the destination domain in the second RewriteCond. Hope this helps. -- Muad'Dib Edited November 4, 2012 by Muad'Dib (see edit history) Link to comment Share on other sites More sharing options...
chetwyn Posted November 4, 2012 Author Share Posted November 4, 2012 Hi Muad'Dib I tried it out but I put me in a loop when I typed in www.iconhomeware.com ? Link to comment Share on other sites More sharing options...
Muad'Dib Posted November 5, 2012 Share Posted November 5, 2012 (edited) Hummm ok. Let's try it an other way. # URL rewriting module activation RewriteEngine on # Redirect all to www.iconhomeware.com.au RewriteCond %{HTTP_HOST} !^www.iconhomeware.com.au [NC] RewriteRule ^(.*)$ www.iconhomeware.com.au/$1 [R=301,L] Hope this works for you. Cheers! PS: Your domain DNS are set properly? -- Muad'Dib Edited November 5, 2012 by Muad'Dib (see edit history) Link to comment Share on other sites More sharing options...
chetwyn Posted November 5, 2012 Author Share Posted November 5, 2012 Hi Muad'Dib Yes, but it keep looping Link to comment Share on other sites More sharing options...
chetwyn Posted November 5, 2012 Author Share Posted November 5, 2012 Seems to be working ok now. I probably did it the worst possible way RewriteEngine on # URL rewriting rules rewritecond %{https} =off RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} iconhomeware\.com\.au [nc] rewriterule ^(.*)$ http://www.iconhomeware.com.au/ [r=301,nc] rewritecond %{https} =off RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} iconhomeware\.com [nc] rewriterule ^(.*)$ http://www.iconhomeware.com.au/ [r=301,nc] rewritecond %{https} =off RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} www\.iconhomeware\.com [nc] rewriterule ^(.*)$ http://www.iconhomeware.com.au/ [r=301,nc] rewritecond %{https} =on RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} ^iconhomeware\.com\.au [nc] rewriterule ^(.*)$ https://www.iconhomeware\.com\.au/$1 [r=301,nc] RewriteCond %{HTTPS} !=on RewriteRule ^admin836/.* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] RewriteCond %{QUERY_STRING} ^(%2d|-)[^=]+$ [NC] RewriteRule ^(.*) $1? [L] Link to comment Share on other sites More sharing options...
Muad'Dib Posted November 5, 2012 Share Posted November 5, 2012 I have to say I am quite surprised it is even working But well, if it works, it works As far as I am aware, if you need to put [NC, OR] when you have more than one RewriteCond for a RewriteRule so it gets to the next one (except for the last one which does not require a OR because it is the last condition) From what I can see you are playing around with the HTTPS feature (which was not in your original question), and the above example of mine should simply redirect any of your domains to www.iconhomeware.com.au regardless of what it originally was and regardless of if it was HTTP or HTTPS (I may have forgotten to escape the dots, true fact but I do not think that is needed tbh I never do it on my .htaccess, it cannot hurt thought). RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] is enough and rewritecond %{http_host} ^iconhomeware\.com\.au [nc] is useless because included in first condition and in fact not even read (you put no OR). In short from what I can see many of your rules are either not read at all or just duping each others. Maybe you misread the !^ in the first condition which means anything but the destination domain, and iconhomeware.(com|com.au) is indeed different from www.iconhomeware.com.au so should trigger the condition But if it works, do not fix it! (or at least make a copy of it before trying) I also had some headaches with my own .htaccess for complex url rewriting, so I know very well how annoying it can be :-P Good Luck! Cheers! -- Muad'Dib Link to comment Share on other sites More sharing options...
chetwyn Posted November 9, 2012 Author Share Posted November 9, 2012 Hi Muad'Dib, hey - thanks for all your help. Really appreciate it dude! I've ended up doing this (it's probably the worst solution known to man but seems to work): rewritecond %{https} =off RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} iconhomeware\.com\.au [nc] rewriterule ^(.*)$ http://www.iconhomeware.com.au%{REQUEST_URI} [r=301,nc] rewritecond %{https} =off RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} iconhomeware\.com [nc] rewriterule ^(.*)$ http://www.iconhomeware.com.au%{REQUEST_URI} [r=301,nc] rewritecond %{https} =off RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} www\.iconhomeware\.com [nc] rewriterule ^(.*)$ http://www.iconhomeware.com.au%{REQUEST_URI} [r=301,nc] rewritecond %{https} =on RewriteCond %{HTTP_HOST} !^www\.iconhomeware\.com\.au [nc] rewritecond %{http_host} ^iconhomeware\.com\.au [nc] rewriterule ^(.*)$ https://www.iconhomeware\.com\.au/$1 [r=301,nc] RewriteCond %{HTTPS} !=on RewriteRule ^admin836/.* https://%{SERVER_NAME}%{REQUEST_URI} [R,L] RewriteCond %{QUERY_STRING} ^(%2d|-)[^=]+$ [NC] RewriteRule ^(.*) $1? [L] Link to comment Share on other sites More sharing options...
joannaleng Posted September 5, 2013 Share Posted September 5, 2013 have you checked with your hosting package that does redirect? I believe it can be done there and you do not need to modify your files manually. it should fall under domain/redirects Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now