-1

I need to do a redirect to the transition from www passed on without www. I uncomment this part in .htaccess. But when I go to the website link www.site.com I get an error: This webpage is not available

# To redirect all users to access the site WITHOUT the 'www.' prefix,
# (http://www.example.com/... will be redirected to http://example.com/...)
# uncomment the following:
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]

Without www site works. Server version: Apache/2.2.22 (Debian)

In the firebug displays 3 error:

Failed to load resource: net::ERR_NAME_NOT_RESOLVED
Failed to load resource: net::ERR_CACHE_MISS
GET _http://www.example.com/ net::ERR_NAME_NOT_RESOLVED
6
  • What's in server's error log? For molot.pl it simply worked, done exactly the same way on stock .htaccess file, so your situation is somehow different - and only you or your admin can see why.
    – Mołot
    Dec 9 '14 at 8:13
  • In the error.log nothing Dec 9 '14 at 8:21
  • ERR_NAME_NOT_RESOLVED suggest some non-printable character in name you put in .htaccess, like windows line ending. Or Russian letter that just happen to look like English one, but in fact isn't. Things like that.
    – Mołot
    Dec 9 '14 at 8:35
  • So I'm using the default .htaccess only 2 lines uncommented. What else could be wrong? Dec 9 '14 at 8:51
  • Let us continue this discussion in chat. Dec 9 '14 at 8:52
0

Use the following .htaccess rule when user enter in browser sitename.com then it will run as www.sitename.com.

Here we write the rewrite rule condition. For more details please visit following the website: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html

**RewriteCond %{HTTP_HOST} ^sitename.com$
RewriteRule (.*) http://www.sitename.com/$1 [R=301,L]** 
1
  • That is the opposite of what the question asks for.
    – rooby
    Aug 15 '15 at 3:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.