2

Basically, i want to have these

My current htaccess is this.

Options -Indexes
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?url=$1 [QSA,NC,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}$1

It works fine this way, but when you manually go to http://domain.com, and change it to https://domain.com, it added two sets of index.php.

Any ideas please?

Stephan Muller
  • 27,018
  • 16
  • 85
  • 126
Hush
  • 23
  • 3
  • 1
    I'm confused. If http goes to https, and non-www goes to www, then `http://domain.com` should go to `https://www.domain.com` right? Both https and www applied. – Stephan Muller Sep 11 '14 at 20:31
  • exactly my point, which is not happening using this current htaccess i have. well partly. as it adds two sets of index.php if you manually go edit the url. – Hush Sep 11 '14 at 20:35

1 Answers1

1

What I can see to be an issue with your code is that you have $1 on the WWW and HTTPS redirects, which would add the request URI path at the end twice, since you already have %{REQUEST_URI}:

Options -Indexes +FollowSymLinks

RewriteEngine On
RewriteBase /

RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}:443%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?url=$1 [QSA,NC,L]

Also it would be easier if you first redirect HTTP to HTTPS (if needed) and then check whether or not the WWWW is missing to redirect (again if needed).

Could probably leave the HTTPS rule without [R=301,L] but if the URL is already right we want to avoid processing more rules.

Keep in mind that the ORDER of your rules is very important.

Prix
  • 19,417
  • 15
  • 73
  • 132
  • ok so so close. when url is https:// www and you manually remove www from it, it returns the https:// www back with no added index.php which is good. but now if the url is https and you manually remove S from it it will return http without the S on it.. i really appreciate the help – Hush Sep 11 '14 at 20:41
  • that fixed it. its exactly what i want to accomplish. thank you! – Hush Sep 11 '14 at 20:49