How to generate "www" in the url automatically when I enter without it [duplicate]

StackOverflow https://stackoverflow.com/questions/23560203

  •  18-07-2023
  •  | 
  •  

Pregunta

I have this site mamgrow.lt. I want to enter mamgrow.lt in the browser and that www would appear automatically in the link after I enter it. Is it possible?

mamgrow.lt ----> ENTER ----> www.mamgrow.lt

Or should I simply redirect user to www.mamgrow.lt when he enters?

¿Fue útil?

Solución

You have to create .htaccess and paste this code:

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

See How to create .htaccess file

Otros consejos

If you are using Apache as a webserver you can do this using a .htaccess file:

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

Here is also a generator for creating proper redirects.

Yes, it is possible using .htaccess:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top