Pregunta

Small problem here, before changing my site to CMS, I have encountered a problem with redirecting all https:// requests to http://.

I have had the following in my .htaccess, which was doing all that

 RewriteCond %{SERVER_PORT} ^443$
 RewriteRule ^(.*)$ http://www.mysite.net/$1 [L,R=301]

but after changing it to CMS that requires different setup, I can no longer use the above mentioned code, since it does not do what it was intended to do in the first place.

Here is my current setup from .htaccess

 RewriteEngine On
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-l
 RewriteRule ^(.*)$ index.php/$1 [QSA,L,NC]
 RewriteCond %{HTTP_HOST} !^(www\.)mysite\.net$ [NC]
 RewriteRule ^(.*)$ http://www.mysite.net/$1 [L,R=301]
 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.net/.*$ [NC]
 RewriteRule \.(gif|jpg|png|tif|js|css|xls|xlsx|zip|rar|pdf|ods|ots)$ - [F]

Can you please advise me on how to do it all correctly, since I really do not want to double up all site content because of this problem and would rather redirect it all to the one consistent protocol.

thanks in advance

¿Fue útil?

Solución

Have your .htaccess like this:

 RewriteEngine On
 RewriteBase /

 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteRule ^ http://www.mysite.net%{REQUEST_URI} [L,R=301,NE]

 RewriteCond %{HTTPS} on [OR]
 RewriteCond %{HTTP:X-Forwarded-Proto} https [OR]
 RewriteCond %{SERVER_PORT} ^443$
 RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

 RewriteCond %{HTTP_REFERER} !^$
 RewriteCond %{HTTP_REFERER} !^http://(www\.)?mysite.net/.*$ [NC]
 RewriteRule \.(gif|jpg|png|tif|js|css|xls|xlsx|zip|rar|pdf|ods|ots)$ - [F,NC]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME} !-l
 RewriteRule ^(.+)$ index.php/$1 [L]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top