Forum Moderators: mack

Message Too Old, No Replies

Help! /index.html etc and trailing slash

         

SueBee

6:57 pm on May 28, 2006 (gmt 0)

10+ Year Member



Yesterday I got almost no traffic from MSN so today I typed in my main search phrase and there I was in a good position on page 1.
I clicked on the link to my site and got 'The domain "example.comindex.html" is invalid.'

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]

SueBee

3:12 pm on May 29, 2006 (gmt 0)

10+ Year Member



Actually www.mysite.com/index.html doesn't work. Now I'm really puzzled. Guess I need to empty out the htacces altogether and think about things.

SueBee

7:16 pm on May 29, 2006 (gmt 0)

10+ Year Member



Emptying out htaccess allows that url to work.

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.

MichaelBluejay

8:21 pm on May 29, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Your site should work with our without the WWW. without your doing anything special. If it doesn't then your webhost has done something screwy (and I might suggest considering using another webhost).

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.

SueBee

12:59 am on May 30, 2006 (gmt 0)

10+ Year Member



Thanks Michael.
I tried your code. That didn't work either. So I went to my site's support and filed a ticket with them about it.

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

jdMorgan

1:21 am on May 30, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The orginally-posted code, if placed in .htaccess, would redirect www.example.com/index.html to example.comindex.html -- Note the missing slash. Since that's an invalid domain name, it's sure to cause trouble. The code would work fine if placed in httpd.conf or conf.d, due to subtle path differences between code in those contexts and the .htaccess context.

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]

The code posted by MichaelBluejay had a small syntax error that was introduced by posting on this forum. The space between "}" and "!" was deleted, which would have caused a 500-Server Error. You can replace my second rule above with this corrected version, if you wish to redirect all domains except example.com:

# 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]

Jim

SueBee

1:53 am on May 30, 2006 (gmt 0)

10+ Year Member



Thank you so much Jim. Now it's perfect!
Sue