mardi 28 novembre 2017

https www to non www https not working using htaccess

I am trying to www to non www redirect with some conition 1) http to https 2) www to non www 3) and add slashes at end

My Code is

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.[a-z0-9]+$ [NC]
RewriteRule ^(.*[^/])$ http://ift.tt/2juHNuq [L,R=301]

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

This code works fine but only 1 condition not works for me The code works for http to https add slashes at end www to non www

Condition which works fine are 1) http://ift.tt/2ju57bx (it redirect if abc exist but if abc is 404 it not works)

2) http://ift.tt/2hXx5fp

3) http://ift.tt/2juHPCy

all redirect to http://ift.tt/2hXVp0w

But the condition which not work for me is

5) http://ift.tt/2jtVadZ (no slashes) it not redirect to http://ift.tt/2hXVp0w

So final observation is that if there is a 404 page then it not works fine with www.

Live example: http://ift.tt/2hZMVGs (This is not working) http://ift.tt/2juHQX8 (This is working)




Aucun commentaire:

Enregistrer un commentaire