質問

I'm using html5 boilerplate and I'm trying to test if my htaccess is working properly. When I type in www.domain.com into chrome or firefox it does not redirect. I'm thinking maybe this is just some browser gimmick though, similar to how Chrome hides the http:// even though its there.

I have checked using chrome dev tools and firebug, and under the request headers it shows whatever I enter in as the "Host"... both with www. and without it... so I dont really know if its working

# ----------------------------------------------------------------------
# Suppress or force the "www." at the beginning of URLs
# ----------------------------------------------------------------------

<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
役に立ちましたか?

解決

The rule is OK.

Please check the following:

  • Did you enabled mod_rewrite in your .htaccess via RewriteEngine On?
  • Is mod_rewrite module loaded in Apache at all? Try moving your instructions outside of <IfModule mod_rewrite.c> to see if it will generate any server errors (indication that mod_rewrite is not loaded).
  • Check if .htaccess is allowed to be used.

As to www or non -- see these topics on Webmasters part of StackExchange:

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top