I am trying to redirect to
https://example.com from https://www.example.com, http://example.com, http://www.example.com
------------------ and ------------------
https://example.com/sub_page/pages from
https://www.example.com/sub_page/pages, http://example.com/sub_page/pages,
http://www.example.com/sub_page/pages
on .htaccess but my sub_pages are not redirecting properly. probably because of conflicting codes below. I read many articles on Internet but do not fount useful.
my .htaccess file
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
I think you got my whole point. In short, I want to redirect all requests to non=www and https. Please help me with this,
My Answer:
You can combine both of your rules into one to avoid conflicts. Here is an updated version of your .htaccess file:
RewriteEngine On
# Redirect to https://example.com
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
This should redirect all requests to non-www and https. Make sure to clear your browser cache before testing the changes.
Rate this post
3 of 5 based on 5357 votesComments