0

The redirect with .htaccess of the main domain without "www" like "mydomain.com" doesn't work, leaving the address in the ordinary http://, so what's wrong with this code? and how to force the redirect of all addresses to https://?

ErrorDocument 404 /404.php RewriteEngine On RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^www.(.*) [NC] RewriteRule ^(.*) https://%1/$1 [R=301,L] RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 
5
  • Where's the code for that? You are only redirecting requests starting with www Commented Aug 20, 2019 at 8:52
  • I've a index.php that handle with the requests, my only issue is that only the www was redirecting to https as you pointed, and as my knowledge in htaccess is really poorly I stucked with this problem, to redirect the http, something like this %{HTTP_HOST} ^http.(.*) [NC] exist ? Commented Aug 20, 2019 at 9:18
  • 1
    You should check the vocabulary ;) HTTP_HOST contains the host. That might start with http, but that is not common. Usually it contains www.domain.com Commented Aug 20, 2019 at 9:46
  • Possible duplicate of Redirect non-www to www in .htaccess Commented Aug 20, 2019 at 9:46
  • Possible duplicate of .htaccess redirect www to non-www with SSL/HTTPS Commented Aug 20, 2019 at 17:55

1 Answer 1

1

Check these modified rules forcing without www and ssl

RewriteEngine On # force to non-www RewriteCond %{HTTP_HOST} ^www.(.*) [NC] RewriteRule ^(.*) https://%1/$1 [R=301,L] # force to ssl RewriteCond %{HTTPS} off RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L] RewriteCond %{SCRIPT_FILENAME} !-f RewriteCond %{SCRIPT_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [L] ErrorDocument 404 /404.php 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.