Forum Moderators: phranque

Message Too Old, No Replies

Rewrite domain.com -> domain.com/index.html

         

JustKia

4:06 pm on Oct 19, 2007 (gmt 0)

10+ Year Member



I'm using rewrite based on the users browser to direct to different index page.

This is what I have so far

# MS Internet Explorer - Mozilla v4
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4(.*)MSIE
RewriteRule ^index\.html$ /v20.html [L]

# All other browsers
RewriteRule ^index\.html$ /v21.html [L]

This works just fine except for one small problem.
If a user hits www.domain.com instead of www.domain.com/index.html they don't get the relevant page.

Those that hit www.domain.com/index.html get the correct page - no problem.

However as I will be using an iframe on those pages (v20.html and v21.html) then I'd be happy if all pages got directed to v20 or v21

I guess what I'm trying to say is can the rules above be written more like this?

# MS Internet Explorer - Mozilla v4
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4(.*)MSIE
RewriteRule <anyfile>$ /v20.html [L]

# All other browsers
RewriteRule <anyfile>$ /v21.html [L]

Kia

**edit to add**
I don't mind the user seeing v20.html/v21.html in the adress bar - it doesn't need to be hidden.

[edited by: JustKia at 4:26 pm (utc) on Oct. 19, 2007]

Quadrille

5:18 pm on Oct 19, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't comment on what you are trying to do, but I do wonder why you are trying to do it.

Domain.com is the single most important URL a site has - and will ever have. Easier to remember, easier to spell, easier to get links to, a permanent, central focus for SEO .... and so on.

It's almost invariably better to be directing visitors TO domain.com - not away from it.

JustKia

6:16 pm on Oct 19, 2007 (gmt 0)

10+ Year Member



It's not that I want to direct them away from it but I have pages that depend on the users browser.

If the user is using IE 5.5/6 then I need them to get a different page to those using Firefox.

I have the .htaccess that will rewrite index.html to either v20.html or v21.html
However when the user types in www.domain.com the .htaccess file does NOT work.
If the user types in www.domain.com/index.html the .htaccess does work.
But most users don't type in the index.html part of an url.

So I need help with editing the .htaccess file so that I can deliver the right pages to the right people =)

Which way it's done I don't mind.
The site is basically to be a storage site for recipes that are shared through a yahoo mailing list.
Yes I know yahoo archives, but I have a specific layout that I want (women eh?) and I have other stuff I want to add.

g1smd

11:57 pm on Oct 19, 2007 (gmt 0)

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



You need a rewrite here.

If you were to use a redirect then each of the pages that users are redirected to could be indexed, and then people with the wrong browser would arrive there direct from the SERPs.

JustKia

5:37 am on Oct 20, 2007 (gmt 0)

10+ Year Member



And that's what I'm using.
My .htaccess so far is in my first post and uses rewrite.

My problem is that with the current .htaccess it only works if the user types in www.domain.com/index.html which of course most users do not.

So, I'm looking to fix my .htaccess so that it will work when the user goes to www.domain.com whereas at the moment it only works if the user goes to www.domain.com/index.html

Ideally if the user its ANY page it will give them v20.html or v21.html (based on their browser) as the content pages are called into an iframe and shouldn't be viewed alone, but won't be disasterous if they do.

[edited by: JustKia at 5:55 am (utc) on Oct. 20, 2007]

g1smd

6:33 am on Oct 20, 2007 (gmt 0)

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



If the user ever got to see the v20 or v21 file names that would be because you used a redirect. I was just confirming that would be a bad idea. You initial assumption about using a rewrite is the correct one.

In your rewrite, the RewriteCond just needs to test for %{REQUEST_URI} being / as well as your existing condition, and only those, and you have cracked it.

If it tested for either / or for /index.html then you would be promoting two URLs for the same content; Duplicate Content. Try to avoid that. Test only for a filepath of "/" in the rewrite request.

So, before the rewrite you need two further rules. You need to redirect (301) requests for all non-www to www for all files on the site, and before that you need a to have a specific 301 redirect for any (www or non-www) /index.html to be redirected to www.domain.com/ too.

JustKia

9:11 am on Oct 20, 2007 (gmt 0)

10+ Year Member



OK I get the bit about non www to www but is that really needful? The site operates fine from either url, and redirecting /index.html to www.domain.com.

I can't seem able to get the
RewriteRule ^index\.html$ /v20.html [L]
RewriteRule ^index\.html$ /v21.html [L]

to test for just / rather than index.html

I've tried
^/$ - gives 500 error
^(.*)/$ - gives 500 error
tried a few other things similar but got 500 errors.
^domain\.com$ - doesn't give the user the v20 or v21 page
^domain\.com/$ - doesn't give the user the v20 or v21 page

I guess I'm missing something basic but I keep giving myself 500 errors.

JustKia

3:21 pm on Oct 20, 2007 (gmt 0)

10+ Year Member



Well in the end this served my purpose:
RewriteCond %{HTTP_USER_AGENT} ^Mozilla/4(.*)MSIE
RewriteRule ^$ v20.html [L]

RewriteCond %{HTTP_USER_AGENT}!^Mozilla/4(.*)MSIE
RewriteRule ^$ v21.html [L]

Thanks for your help

Kia x

g1smd

6:56 pm on Oct 20, 2007 (gmt 0)

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



>> I get the bit about non-www to www but is that really needful? The site operates fine from either url <<

If you have read anything about Duplicate Content issues any time in the last 3 or 4 years, you'll realise the necessity of including those redirects before the rewrite kicks in.

JustKia

8:04 pm on Oct 20, 2007 (gmt 0)

10+ Year Member



I haven't come across it until I started looking for the answer to this situation to be honest.

Guess I best go searching and read up =)

g1smd

10:48 pm on Oct 20, 2007 (gmt 0)

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



There are loads of examples here in the forum.

Give it a go and report back how you get on.