Forum Moderators: mack
MSN was pointing to
example.com/index.html
Well, I thought I could fix that in htaccess by redirecting example.com/index.html to just example.com
then I tried looking up example.com/index.html/ - that wouldn't work. so I also redirected that to example.com
Here's what I had:
RedirectMatch permanent ^/index.html$ http://example.com
RedirectMatch permanent ^/index.html/$ http://example.com
Then my home page wouldn't come up at all :( So I removed them all.
so how do I get "example.com/index.html" which is somehow turning into example.comindex.html even though I checked the source and it was correct with the traling slash, to work?
quite a few links to my site have the index.html there - I originally had index.htm and had to change it one time when I changed my host.
I did do a redirect fom www.example.com to example.com. I think that that is fine and working. I don't think it should be a problem?
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ http://example.com$1 [L,R=301]
I was trying to get all my site with no www but maybe there isn't any way to do that :(
There shouldn't be links to me with the www prefix, but lots of people just put it in there in any case, just as I might put a link for someone without the www. although their site does want it.
I really don't understand the necessity of having www. Surely 99.9999% of urls are world wide web - I think it should be the default unless some other prefix is put there. Do people really want to type an extra 4 digits every time they want to go to a website? Guess I don't understand something.
Well, if anyone has any ideas how I can do a redirect from www.mysite.com with or without /index.html or index.html/ I'd really appreciate it.
This .htaccess code will redirect the WWW. version to the plain version under normal circumstances, but whatever your webhost seems to have done might override this.
RewriteCond %{HTTP_HOST}!^yourdomain\.com
RewriteRule (.*) [yourdomain.com...] [R=301,L]
This is what I use on my own domains. I've redirected from the WWW. version to the plain version for years, but as you noticed, people insist on linking to the WWW. version anyway even though the WWW. never, ever, ever appears when they're browsing my site. Go figure.
I had thought that since I had a completely empty htaccess file to start with that they weren't involved in it. So I really appreciate you pointing out to me that it's almost certainly something that they are doing.
Sue
To correct the original /index.html problem without creating an infinite redirection loop, and to strip "www" without creating an invalid domain problem in .htaccess, I'd suggest:
# mod_rewrite setup
Options +FollowSymLinks
RewriteEngine on
#
# Redirect direct client /index.html requests to "/" (does not affect DirectoryIndex accesses)
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html
RewriteRule ^index\.html$ http://example.com/ [R=301,L]
#
# Redirect requests for resources in www domain to same resources in non-www domain
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) http://example.com/$1 [R=301,L]
# Redirect requests for resources in any domain except example.com to same resources in example.com
RewriteCond %{HTTP_HOST} !^example\.com
RewriteRule (.*) http://example.com/$1 [R=301,L]