I've been struggling with getting my URL's to redirect correctly.
What I would like to happen
To forward to https://www.ourwebsite.co.uk if any of the following happens:
- User accesses the website from ( http:// OR https:// )ourwebsite.com / .net / .org / .mobi / .eu
- User doesn't enter from HTTPS (443)
- User enters the site without www.
- Basically, they have to visit the website via https://www.ourwebsite.com or not at all.
What is happening now
- If a user goes to http://ourwebsite.com, it takes them to https://www.ourwebsite.com (CORRECT)
- If a user goes to https://ourwebsite.com, it doesn't redirect at all (INCORRECT)
- If a user goes to https://www.ourwebsite.com, it redirects to https://ourwebsite.co.uk (INCORRECT)
My .htaccess file currently contains:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?ourwebsite\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?ourwebsite\.net$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?ourwebsite\.eu$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?ourwebsite\.mobi$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?ourwebsite\.it$ [NC]
RewriteRule ^(.*)$ https://www.ourwebsite.co.uk/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.ourwebsite.co.uk/$1 [R=301,L]
I have tried...
I have tried many different examples I found online, they work individually but they don't seem to work together. I have split the non 443 rule and added it separate at the bottom, but this hasn't changed anything.