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

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

  •  18-07-2023
  •  | 
  •  

Вопрос

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?

Это было полезно?

Решение

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

Другие советы

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]
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top