Forum Moderators: phranque
I want to redirect URLs like
www.domain.com/tagword/main/index.html
to
www.domain.com/tagword/main/
and
www.domain.com/tagword/main/sub/index.html
to
www.domain.com/tagword/main/sub/
after the redirection there are two rules which will open the index.html page automatically, All I want is to hide index.html from the URLs.
I am not sure what kinda rule should I use for this?
P.S tagword is a hardcoded entity in the URL which appears always so only main and sub are the variables.
First, remove "index.html" from the links on all of your pages -- A multi-file editor (many free/shareware programs available) is handy for this purpose. It is the links on your pages which determine the URL, while internal rewrites (including DirectroyIndex) associate a "Web" URL with a server filepath.
Then redirect only client requests for "/index.html" to "/". This restriction is necessary to prevent a loop, since DirectoryIndex will rewrite "/" back to "/index.html" and if you overlook it, you'll create an 'infinite' redirect/rewrite loop.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /tagword/([^/]+/)*index\.html
RewriteRule ^tagword/(([^/]+/)*)index\.html$ http://www.example.com/tagword/$1 [R=301,L]
THE_REQUEST is the HTTP request header as received from the client (browser or 'bot), and might look like this:
GET /tagword/main/sub/index.html HTTP/1.1
Jim
This stops people guessing what underlying technology actually runs the website, and allows a change of technology at any time without exposing new URLs for indexing.
This redirect also forces the correct domain (i.e. www.domain.com) in the redirect.
This redirect therefore goes before the main non-www to www redirect code, so that index URLs are not redirected twice.