.HTACCESS 301 Redirect

Ye' old general discussion board. Basically, for everything that isn't covered elsewhere. Come here to shoot the breeze, shoot your mouth off, or whatever suits your fancy.
This forum is not for asking programming related questions.

Moderator: General Moderators

Post Reply
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

.HTACCESS 301 Redirect

Post by malcolmboston »

I have the following code in my .htaccess file

Code: Select all

 
redirect 301 /index.php http://www.mysite.co.uk/
 
the purpose of this is anyone visiting http://www.mysite.co.uk/index.php will automatically be redirected to http://www.mysite.co.uk/

something is obviously wrong however as firefox gives me the following message
Firefox wrote: Redirect Loop

Redirection limit for this URL exceeded. Unable to load the requested page. This may be caused by cookies that are blocked.

The browser has stopped trying to retrieve the requested item. The site is

redirecting the request in a way that will never complete.

* Have you disabled or blocked cookies required by this site?
* NOTE: If accepting the site's cookies does not resolve the problem, it is probably a server configuration
issue and not your computer.
Ive done a search and cant seem to find whats wrong with my line of code, can someone point me in the right direction?

Cheers, Mal
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: .HTACCESS 301 Redirect

Post by matthijs »

I think you should change the rule to

Code: Select all

 
Redirect permanent /oldpage.html http://www.newsite.com/new-page/
 
At least, that's what I did when I had to do the same thing.

Also, do you have any other rules in the htaccess file? Sometimes it's the combination of certain rules which cause the loop.
matthijs
DevNet Master
Posts: 3360
Joined: Thu Oct 06, 2005 3:57 pm

Re: .HTACCESS 301 Redirect

Post by matthijs »

Mal, are you sure that rule is actually needed? Normally apache is configured in such a way that yoursite.com/ automatically calls the index.php or index.html pages. Redirecting index.php to the root yoursite.com/ will therefore cause an infinite loop.

So my guess is that you should not write that rule.
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Re: .HTACCESS 301 Redirect

Post by JayBird »

Perhaps it is a server setting becuase i have just tried it on my server and it works just as expected.
malcolmboston
DevNet Resident
Posts: 1826
Joined: Tue Nov 18, 2003 1:09 pm
Location: Middlesbrough, UK

Re: .HTACCESS 301 Redirect

Post by malcolmboston »

thanks for that Mark, ill look into it.
Post Reply