Forum Moderators: phranque

Message Too Old, No Replies

'Simple' htaccess confusion

redirection

         

bobmould

5:00 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



Hi all,

I hope you can help with a simple problem I have. I have some code in my .htaccess file that redirects the front page to [my web site] at www.example.com/index.php

I want my canonical homepage to be www.example.com

However I cannot figure out how to successfully alter the code in .htaccess to achieve this.

The code in question reads:

RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule (.*) http://www.example.com/$1 [L,R=301]
#
RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^index\.html$ "http\:\/\/www\.example\.com\/index\.php" [R=301,L]

Can someone please lend a quick hand?

Many thanks

Bob

[edited by: jdMorgan at 3:00 am (utc) on Apr 28, 2010]
[edit reason] example.com & formatting [/edit]

g1smd

5:45 pm on Apr 26, 2010 (gmt 0)

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



This is a popular question here.

In fact, it was asked and answered in the last 24 hours or so.

Check recent threads for ideas.

It's always a good idea to link to URL without index filename. Additionally the redirect to "/" eliminates Duplicate Content issues.

The existing code above redirects requests for index.htm to index.php, so doesn't need a lot of changes to redirect to a different URL. Be aware that the target URL does not need to escaped in any way.

Your existing code forms a redirection chain for some requests. Make sure the "index" redirect is first and the general non-www to www redirect is last. Use RewriteRule directives for both.

bobmould

7:58 pm on Apr 26, 2010 (gmt 0)

10+ Year Member



Thanks for the reply. Unfortunately, I am no coder and I really don't have a clue how to change the code correctly. Every time I attempt I get the 'Too many redirects' error. I can't find a thread with the answer as I don't know what to look for or know what the answer would look like when I find it.

g1smd

8:03 pm on Apr 26, 2010 (gmt 0)

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



I would caution against adding any code to your server that you do not understand. This is server configuration code you are dealing with here and incorrect configuration can literally put you and your site out of business.

A search for 'index redirect' brings up a few candidates; many have very detailed descriptions so I'll save time retyping stuff that has been covered many times before: [google.com...]