homepage Welcome to WebmasterWorld Guest from 54.197.108.124
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
htaccess index.html file to root
Silver007A




msg:4499357
 2:26 pm on Sep 24, 2012 (gmt 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]

 

g1smd




msg:4499363
 2:39 pm on Sep 24, 2012 (gmt 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.

Silver007A




msg:4499368
 2:54 pm on Sep 24, 2012 (gmt 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]

phranque




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

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




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

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




msg:4499467
 9:35 pm on Sep 24, 2012 (gmt 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]

Silver007A




msg:4499468
 9:45 pm on Sep 24, 2012 (gmt 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

g1smd




msg:4499469
 10:15 pm on Sep 24, 2012 (gmt 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.

phranque




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

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




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

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




msg:4499521
 1:19 am on Sep 25, 2012 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved