English 中文(简体)
Are these two re-writes the same?
原标题:

How are the following different? Ignore the domain names.

RewriteCond %{HTTP_HOST} ^www.example.com$ [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]


RewriteCond %{HTTP_HOST} !^www.yourdomain.com
RewriteRule (.*) http://www.yourdomain.com/$1 [L,R=301]

The difference is "^"?

What I basically want to do is have my site as http://yourdomain.com and never have the www appear. For a start its shorter and its good for SEO as my site won t be judged as two sites. One with www and one without.

Thanks all

最佳回答

No, they are not the same.

The first says, redirect to the host example.com if the host is www.example.com.
The second says, redirect to www.example.com if the host is not www.example.com.

And even if you would rewrite the second to the following (having both rules redirecting to example.com:

RewriteCond %{HTTP_HOST} !^example.com$
RewriteRule (.*) http://example.com/$1 [L,R=301]

So that it would redirect to example.com if the host is not example.com. The result might be the same if the host can only be www.example.com and example.com. But if it can have more values than that (e.g. foobar.example.com), the your first rule would not redirect while my would redirect.

问题回答

暂无回答




相关问题
Using SimplePie with CodeIgniter and XAMPP

I am using CodeIgniter 1.7.2 with XAMPP 1.7.2 on a Windows computer. I am trying to make use of SimplePie. I followed all the instructions I could find: a copy of simplepie.inc is in my applications/...

Multiple Sites with common files

I have developed over 50 sites that all use the exact same files other than CSS and IMAGES, I currently duplicate the files each time I create a new site and upload different css and images. What ...

http server validation

I finish a litle http server, writing from scratch. I would like to be sure that my imlementation is conforme to the HTTP specifications. W3C give us tools for HTML/XML conformance, but i see nothing ...

热门标签