htaccess rule on my website

0

I have this rule in my htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) / [L]

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

I want if the url does not start with ' link .', redirect it and start with it.

    
asked by Franklin'j Gil'z 01.03.2017 в 22:20
source

2 answers

4

You can prefix the rule

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

To your rule RewriteCond %{HTTPS} off so that it stays

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

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

This would generate three types of redirection

request: http://www.midominio.com
  redirect-> https://www.midominio.com (regla2)

request: http://midominio.com
  redirect-> https://www.midominio.com (regla1)

request: https://midominio.com
  redirect-> https://www.midominio.com (regla1)

The fourth case is

request: https://www.midominio.com

And that is not subject to redirection.

    
answered by 01.03.2017 / 22:56
source
1

After the RewriteEngine On add the following line:

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

The rest of your htaccess could look like this:

RewriteEngine On

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

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule (.*) / [L]

RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    
answered by 01.03.2017 в 22:57