direct with htaccess

Asked

Viewed 44 times

0

I have a project where when the user type the site with www, it gives error. I checked the server and there is no htaccess in the root folder. With this, I would like to know how to make the user type www.site.com.br or http://site.com.br was directed to the site folder/.

2 answers

1

Try the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^seusite.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.seusite.com$
RewriteRule ^(.*)$ http://www.seusite.com/site [R=301,L]

1


Because there is no file, just create it in your root folder!

And add some of those codes, which suit your situation better:

Redirect addresses without www to addresses with www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^seusite.com.br
RewriteRule ^http://www.seusite.com.br%{REQUEST_URL}[L,R=301]

Redirect URL’s with www to an address without www

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301,L]
  • Thank you all.

Browser other questions tagged

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