Douglas Cottrell
Douglas Cottrell

Reputation: 281

.htaccess http to https

I am having a conflict between a couple of redirects causing issues.

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

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://www.mywebsite.org/ [R=301,L]

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

Options +FollowSymLinks -MultiViews
RewriteCond %{REQUEST_FILENAME} !403\.shtml
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*) index.php?a_aid=$1  [NC,L,R=301]

The issue I am running into is that when someone enters a non secure url it forwards them to

http://www.mywebsite.org/index.php?a_aid=https://www.mywebsite.org/url

Upvotes: 0

Views: 145

Answers (1)

Louis Loudog Trottier
Louis Loudog Trottier

Reputation: 487

My bet is that you'll need to add the [L] at the end of your line :

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

The L tag tells the code to stop running if the rule is applied, in your case it keep goin so the last rule is applied..

 RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

i think this is what i sould be.

In this section you wil find the different flag you can apply to your rules. i suggest you add the NC flag too (as for no case) so it match HTTPS also

http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule

Upvotes: 1

Related Questions