Welcome to WebmasterWorld Guest from 54.196.144.100

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

htaccess index.html file to root

     

Silver007A

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

5+ Year Member



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]

g1smd

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

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



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.

Silver007A

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

5+ Year Member



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]

phranque

4:21 pm on Sep 24, 2012 (gmt 0)

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



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.

lucy24

4:45 pm on Sep 24, 2012 (gmt 0)

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



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)?$

Silver007A

9:35 pm on Sep 24, 2012 (gmt 0)

5+ Year Member



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]

Silver007A

9:45 pm on Sep 24, 2012 (gmt 0)

5+ Year Member



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

g1smd

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

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



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.

phranque

10:20 pm on Sep 24, 2012 (gmt 0)

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



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?

lucy24

10:53 pm on Sep 24, 2012 (gmt 0)

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



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.

g1smd

1:19 am on Sep 25, 2012 (gmt 0)

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



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.