Url in htaccess

Asked

Viewed 44 times

0

Is it possible to control the url in htaccess? For example: if you type site.com.br it corrects and places www.site.com.br.

I have a case that some pages go with site.com.br/blog. Others with site.com.br/who-we give error, because it sends to https://site.com/index.php.

The htaccess I’m using is this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

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

## 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 text/html "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 1 month"
</IfModule>
## EXPIRES CACHING ##

(I’m sorry, but I couldn’t find another way to put it here).

1 answer

0

You are redirecting from http to the https correctly. Now you need to redirect to the correct domain:

# Redirecionando do domínio errado (sem www) para o correto (com www)
RewriteCond %{HTTP_HOST} !^www\. # Verifica se tem o www
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Put this after your last rule, that is, after RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}.

  • I did that and now it’s going to https://www.site.com.br/index.php. I wonder if there’s any more bo?

  • Is that your website? Why is the URL right https://www.site.com.br/index.php

  • Can I put the real url? I thought I couldn’t.

  • Yes, but it’s best to leave the environment variables alone.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.