Page is a not externally linkable
- WebmasterWorld
-- New To Web Development
---- Canonical problems?


g1smd - 2:40 pm on Sep 24, 2006 (gmt 0)


>> Some users are using a $ after the first .com, some not

I assume that you are talking about the $1 notation.

If you are referring to the RewriteRule line then I hope I can explain some things here.

In that line you are taking one URL and turning it in to some other.

.

The first bit specifies what the original URL was, the second bit specifies what it becomes.

You can collect up a chunk of URL in a (.*) and then re-use it in a $1 later.

If you had a second (.*) you could reuse it in a $2 later.

You can append ^ and $ around a (.*), or around a whole expression, to denote an exact match like : ^(.*)$ or even ^/somefolder(.*)$ or in this case perhaps ^(.*)index.html$

.

Some examples for your index redirection:

RewriteRule ^index\.html?$ http://www.mysite.com/ [R=301,L]

This takes only the root index.html page and rewrites to the root www.domain.com/ without the index.html appended.
It does not cater for index pages in folders on the site.

.

RewriteRule ^(.*)index\.html?$ http://www.mysite.com/ [R=301,L]

This takes any index.html page (even one in a sub-folder - that's the (.*) bit) and rewrites to the root www.domain.com/ without the index.html appended. It does NOT preserve the folder name - BAD!

.

RewriteRule ^(.*)index\.html?$ http://www.mysite.com/$1 [R=301,L]

This one takes any index.html page (even one in a sub-folder - that's the (.*) bit) and rewrites the URL to the same folder (that's the $1 bit) www.domain.com/folder/ but without the index.html appended.

.

A note about the ? in the RewriteRule ^index\.html?$ part.

RewriteRule ^index\.htm$ - rewrites only for index.htm

RewriteRule ^index\.html$ - rewrites only for index.html

RewriteRule ^index\.html?$ - rewrites both for index.htm and for index.html

.

This stuff is very very powerful. It is logical, but it is not always obvious.


Thread source:: http://www.webmasterworld.com/new_web_development/3092989.htm
Brought to you by WebmasterWorld: http://www.webmasterworld.com