Is there an easy way (preferably with htaccess and mod_rewrite) to force the browser to always access the site using www. prefix (adding it automatically if necessary?)
thank.
Rewritecond %{HTTP_HOST} !www.domain.com RewriteRule ^/(.*)$ http://www.domain.com/$1 [R=301]
or maybe
RewriteCond %{HTTP_HOST} !^www. RewriteRule ^/(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
This is what I use:
$url= $_SERVER["SERVER_NAME"]; $page=$_SERVER["REQUEST_URI"]; if($url == "example.com"){ header("Location: http://www.example.com$page"); }
Source: https://habr.com/ru/post/1738743/More articles:Общая архитектура CMS - web-applicationsAndroid Extend BaseExpandableListAdapter - androidкак генерировать случайное число из массива - javaASP.NET MVC 2 RTM - icon does not appear in Internet Explorer - htmlInsert the infront character of each word into a string using C ++ - c ++calling WinForms programs contextmenustrip - c #Call the named routes in CakePHP in the same way as in Ruby on Rails - ruby-on-railsdjango-регистрация с интеграцией PayPal - djangoSilverlight MouseLeftButtonDown event does not fire - event-handlingNSFetchedResultsController fetch request - update predicate and UITableView - iphoneAll Articles