php - $_SERVER['HTTP_HOST'] shows only domain name without www -
even if in url write "www.", $_server['http_host'] have domain.com without "www."
i can't redirect non-www www because of this. how fix issue?
["http_host"]=> string(8) "ca-fi.ru" ["http_cookie"]=> string(120) "d7b6b86aae18e551749a9da9d54f3daf=floar2lr37318dc76ask49bii5; 849c6485c12558d081c065b4d94a566b=d9iqj8s6oqo41kipg3qaefq497" ["http_user_agent"]=> string(99) "mozilla/5.0 (windows nt 6.1) applewebkit/536.5 (khtml, gecko) chrome/19.0.1084.52 safari/536.5" ["path"]=> string(28) "/usr/local/bin:/usr/bin:/bin" ["server_signature"]=> string(69) " apache/2.2.20 (ubuntu) server @ ca-fi.ru port 80 " ["server_software"]=> string(22) "apache/2.2.20 (ubuntu)" ["server_name"]=> string(8) "ca-fi.ru" ["server_addr"]=> string(13) "192.168.10.12" ["server_port"]=> string(2) "80" ["remote_addr"]=> string(12) "192.168.10.1" ["document_root"]=> string(8) "/var/www" ["request_method"]=> string(3) "get" ["request_uri"]=> string(1) "/" ["script_name"]=> string(10) "/index.php" ["php_self"]=> string(10) "/index.php" ["request_time"]=> int(1338819407)
if want redirect non-www www, i'd recommend not using phps header() function (which assume you're using), use mod rewrite.
create .htaccess file in root directory following content:
rewriteengine on rewritecond %{http_host} ^example.com [nc] rewriterule ^(.*)$ http://www.example.com/$1 [l,r=301]
Comments
Post a Comment