Below is my HTACCESS in which I am redirecting my website with below rules.
https://rosterelf.com will be redirected to https://www.rosterelf.com/
http://www.rosterelf.com will be redirected to https://www.rosterelf.com
rosterelf.com will be redirected to https://www.rosterelf.com/
So basically it will check if url does not have www or https then it will simply direct with it. This is working fine for me.
However, now I want to redirect all my urls with .com.au as well ..
I should be able to redirect https://www.rosterelf.com.au/ to https://www.rosterelf.com/ with same above conditions. By checking https or non www to www.
I have tried various codes like
RewriteCond %{HTTP_HOST} =m.somesite.com.au
RewriteRule (.*) http://www.somesite.com.au/$1 [R,L]
and others by adding in my existing htaccess file but it doesnt work in few cases like in my inner pages .. or without https. Here is my current htaccess file looks like.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
##
## You may need to uncomment the following line for some hosting environments,
## if you have installed to a subdirectory, enter the name here also.
##
# RewriteBase /
##
## Uncomment following lines to force HTTPS.
##
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{SERVER_NAME}/$1 [L,R=301]
# CONDITIONS FOR ONLY LIVE SITE STARTS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# CONDITIONS FOR ONLY LIVE SITE ENDS
##
## Black listed folders
##
RewriteRule ^bootstrap/.* index.php [L,NC]
RewriteRule ^config/.* index.php [L,NC]
RewriteRule ^vendor/.* index.php [L,NC]
RewriteRule ^storage/cms/.* index.php [L,NC]
RewriteRule ^storage/logs/.* index.php [L,NC]
RewriteRule ^storage/framework/.* index.php [L,NC]
RewriteRule ^storage/temp/protected/.* index.php [L,NC]
RewriteRule ^storage/app/uploads/protected/.* index.php [L,NC]
##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/.well-known/*
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/public/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/resized/.*
RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteRule !^index.php index.php [L,NC]
##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} .php$
RewriteRule !^index.php index.php [L,NC]
##
## Standard routes
##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
As you can see above htaccess I have used below 3 lines of code to redirect non www to www and http to https ..
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
Now my question is, how can I make all the existing condition work with able to redirect .com.au to .com ?
Can someone guide me please ..
Thanks
2
Answers
With your shown samples, please have your htaccess with following Rules.
Please make sure you clear your browser cache before testing your URLs.
You can redirect both domains to
https
and addwww.
in single redirect rule. Make sure to keep this new redirect rule before other rules: