Forum Moderators: phranque

Message Too Old, No Replies

index.html - Question.

htaccess and options...

         

micklearn

6:41 am on Jul 15, 2010 (gmt 0)

10+ Year Member



Why doesn't the following code in htaccess redirect to the root domain?

(www.example.com/index.html --> www.example.com/)

Options +FollowSymLinks -Indexes

g1smd

6:43 am on Jul 15, 2010 (gmt 0)

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



I think you forgot to post your code example?

micklearn

4:49 am on Jul 16, 2010 (gmt 0)

10+ Year Member



Thanks for the reply, g1smd - my post was a huge 'copy and paste' debacle on this end. Sorry about that and obviously, I lost the original code that I was trying to use in htaccess. My goal was to redirect www.example.com/index.html to www.example.com/ and use code that would *only* have an effect on the home page and no effect on other folders/pages on the site.

g1smd

11:45 am on Jul 16, 2010 (gmt 0)

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



Does the code need to work only for index.html in the root or should it also work for for index.html in other folders?

The latter is how most sites would be set up. Strip off the index.html for any such URL, redirecting to bare folder at same level.

micklearn

3:51 am on Jul 17, 2010 (gmt 0)

10+ Year Member



I had been thinking of code along the lines of just for index.html in the root, since that appears to be accessible on the site and it shows the same content as the root.

When I visit a page such as www.example.com/example/index.html or if I visit a folder such as www.example.com/example/ they all show up as 403 errors.

There is only one page on the entire site named index.html.

I'm now wondering if I need to create index.html files for all folders. Thanks for your help, g1smd, I really appreciate it.

jdMorgan

5:57 am on Jul 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Many previous threads here: [google.com...]

Jim

micklearn

2:53 am on Jul 21, 2010 (gmt 0)

10+ Year Member



Thanks, Jim! I had missed reading some of the threads on here, while trying to search for a solution. So, is this the correct way for solving all of the possible canonical issues (as described above):


Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.com/ [R=301,L]


Thanks again, I really appreciate your help with this.

Best,
Mick

g1smd

7:21 am on Jul 21, 2010 (gmt 0)

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



It doesn't fix requests for "www" with "appended port number", and it doesn't fix requests for index.html in folder other than root.

Additionally, it creates an unwanted two-step redirection chain for non-www request that includes also index.html.

The index redirect should be listed first. Both redirects could be optimised a lot more.

jdMorgan

6:33 am on Jul 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To wit:

Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
#
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/+]/)*index\.html([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/+]/)*)index\.html$ http://www.example.com/$1 [R=301,L]
#
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]

Jim

micklearn

7:10 am on Jul 25, 2010 (gmt 0)

10+ Year Member



A huge thanks to both of you, and a huge sigh of relief on this end. Been trying to solve this for weeks and have learned a lot in the process. Thanks, again.

Best, Mick