I saw .htaccess Do Not Redirect WWW to WWW, keeping URI string , but for me it does not work
if I go to mysite.com/site/something , I will redirect to mysite.com/something
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
also tried:
RewriteCond %{HTTP_HOST} . RewriteCond %{HTTP_HOST} !^www.mysite.com [NC] RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
change
here's the im code using Alfonso-based Rubalcava based answer:
if (substr($_SERVER['SERVER_NAME'], 0, 3) != 'www') { if ($_SERVER['REQUEST_URI'] == '//site/') { header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.site.com/site/'); exit; } header('HTTP/1.1 301 Moved Permanently'); header('Location: http://www.site.com' . $_SERVER['REQUEST_URI']); exit; }
source share