2

I was trying to edit my htaccess file to redirect from http to https.

This one works for all pages except the homepage for every language:

http://cinqueterre.a-turist.com/deu redirects to https://cinqueterre.a-turist.com/https://cinqueterre.a-turist.com/deu

It's a little complicated script

Here is it:

Update: I improved a little the script, now it's not such complicated, and doesn't work if I add https redirect

DirectoryIndex 1.php index.html$ index.php

ErrorDocument 404 /404.php

RewriteEngine on
Options -Multiviews



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


RewriteCond %{HTTPS_HOST} ^www\.cinqueterre\.a\-turist\.com$ [NC]
RewriteRule (.*) https://cinqueterre.a-turist.com/$1 [R=301,L]

RewriteCond %{HTTPS_HOST} ^cinqueterre.a-turist\.com$ [OR]
RewriteCond %{HTTPS_HOST} ^www\.cinqueterre.a-turist\.com$
RewriteRule ^(rus|ita|fra|deu|ukr|pol|esp)\/index\.php$ https\:\/\/cinqueterre.a-turist\.com\/$1 [R=301,L]


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]


#if its not a directory
RewriteCond %{REQUEST_FILENAME} !-d
#and it has a trailing slash then redirect to URL without slash
RewriteRule ^(.+)/$ /$1 [L,R=301]


Options All -Indexes


## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"
</IfModule>
## EXPIRES CACHING ##


<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</ifmodule>
Zhenya
  • 271
  • 1
  • 4
  • 15
  • possible duplicate of [How to redirect all HTTP requests to HTTPS](http://stackoverflow.com/questions/4083221/how-to-redirect-all-http-requests-to-https) – hjpotter92 Aug 14 '14 at 15:21
  • It didn't work for me. I am trying for about 5 hours to fix it :) – Zhenya Aug 14 '14 at 16:15

1 Answers1

0

Try getting rid of all of your redirects, they're in the wrong place.

You need to add redirects before this rule:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+)$ $1.php [L,QSA]

And you want something like this:

RewriteCond %{THE_REQUEST} \ /+.*index\.php
RewriteRule ^(rus/|ita/|fra/|deu/|ukr/|pol/|)index\.php$ https://cinqueterre.a-turist.com/$1 [R=301,L]

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?cinqueterre.a-turist\.com$ [NC]
RewriteRule ^(.*)$ https://cinqueterre.a-turist.com/$1 [R=301,L]
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • I used only those 5 lines before that rule and it finishes in a loop... Doesn't work – Zhenya Aug 14 '14 at 15:35
  • If I remove the last rule - it doesn't go in loop, but many things doesn't work, that's why I was thinking to leave that big script just fixing it :( I am trying to fix it the whole day.. – Zhenya Aug 14 '14 at 15:40
  • Found the problem, it was in this rule: #if its not a directory RewriteCond %{REQUEST_FILENAME} !-d #and it has a trailing slash then redirect to URL without slash RewriteRule ^(.+)/$ /$1 [L,R=301] – Zhenya Aug 14 '14 at 18:16