Welcome to WebmasterWorld Guest from 54.196.232.162

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess index.html file to root

     
2:26 pm on Sep 24, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Oct 14, 2009
posts: 41
votes: 0


Hi,

I have an html/css site and am trying to get it so index.html doesn't count as another page and duplicate of the root/home page. Can't remember how to do it, but have this htaccess file.

How would I test it as well? If I type www.mydomain.co.uk/index.html it shows and if I type just www.mydomain.co.uk it shows the same. Is that correct or duplicate?

AddHandler x-mapp-php5.1 .php

# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
Options +FollowSymLinks
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://www.mydomain.com/$1 [R=301,L]
2:39 pm on Sept 24, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


The Options line should be first.

The index ruleset should be next. Escape literal periods. The .* bit is very wrong.

The non-www ruleset should be last.

Use the Live HTTP Headers for Firefox extension to look at server headers.

Use example.com in this forum.
2:54 pm on Sept 24, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Oct 14, 2009
posts: 41
votes: 0


Is this any better?

I didn't understand -


Use the Live HTTP Headers for Firefox extension to look at server headers.



# Redirect non-www urls to www
Options +FollowSymLinks
RewriteRule ^(.*)index.php$ http://www.example.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteCond %{HTTP_HOST} !^www\.example.com\.com
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
4:21 pm on Sept 24, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


the ".*" in your regexp is considered "ambiguous, greedy and promiscuous", so you should use a more efficient pattern.

your rulesets include a condition and a rule but you split one up when rearranged.

one of your conditions has an extraneous '.com' in the pattern.

the index ruleset only matches the index.php file but your problem statement indicates an html file.

Live HTTP Headers is an add-on for firefox.
go search for and install it.
4:45 pm on Sept 24, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12704
votes: 244


RewriteRule ^(.*)index.php$
=
RewriteRule ^(([^/.]+/)*)index\.php$

^.* (without capture) is meaningless and superfluous all the time without exception. "There might be some stuff before the part I'm looking for." So is .*$ but you don't see it as often.

%{HTTP_HOST} !^www\.example.com\.com
=
%{HTTP_HOST} !^(www\.example.com\.com)?$
9:35 pm on Sept 24, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Oct 14, 2009
posts: 41
votes: 0


Is this correct then?

# Redirect non-www urls to www
Options +FollowSymLinks
RewriteRule ^(([^/.]+/)*)index\.html$ http://www.example.com/$1 [R=301,L]
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteCond %{HTTP_HOST} !^(www\.example.com\)?$
RewriteRule ^(.*) http://www.example.com/$1 [R=301,L]
9:45 pm on Sept 24, 2012 (gmt 0)

Junior Member

5+ Year Member

joined:Oct 14, 2009
posts: 41
votes: 0


index.html seems to redirect me to the site that owns example.com now.

Can anyone please just show me the code. htaccess is always an enigma to me.

Thanks
10:15 pm on Sept 24, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


When I said "move a ruleset", it meant move both the condition and rule pair together.

Use example.com in this forum, and the real domain name when you use the code on your site.
10:20 pm on Sept 24, 2012 (gmt 0)

Administrator

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Aug 10, 2004
posts:10542
votes: 8


until you can describe the status code chain and relevant response headers it is difficult to solve your problem.
have you installed firefox with the Live HTTP Headers add-on?
10:53 pm on Sept 24, 2012 (gmt 0)

Senior Member from US 

WebmasterWorld Senior Member lucy24 is a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month

joined:Apr 9, 2011
posts:12704
votes: 244


Cut and paste is not being kind to you, is it? Instead of:

1 Options...
2 RewriteEngine...
3 Comment on Rule 1
4 Cond#1
5 Rule#1
6 Comment on Rule 2
7 Cond#2
8 Rule#2

you've got

6 Comment on Rule 2
1 Options...
5 Rule#1
2 RewriteEngine...
4 Cond#1
7 Cond#2
8 Rule#2

The Options... line may have been set already in the host's config file-- probably in a <Directory> section covering all userspaces-- but repeating it will do no harm. The RewriteEngine On line does have to be there; unlike most things in Apache it isn't inherited.
1:19 am on Sept 25, 2012 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


6 1 5 2 4 7 8 - and I thought my instructions were fairly clear. Lrt's get this fixed, debugged and working.

It's important you learn how to do this yourself, so that you can maintain your own code in the future.