PDA

View Full Version : Redirect error



xoggoth
21st January 2015, 10:48
SEO toolkit is showing following error for http://mysite.co.uk/

The link to "http://mysite.co.uk/" has resulted in a redirection to "http://www.mysite.co.uk/" which resulted in another redirection.

Not sure where this is coming from. I use a shopping cart with PHP sessions and all PHP pages needs to be in one directory level. My home page is /pages/home.php.

index.html is:

<!DOCTYPE HTML>
<html lang="en-US">
<head>
<meta charset="UTF-8">
<meta http-equiv="refresh" content="1;url="/pages/home.php">
<script type="text/javascript">
window.location.href = "/pages/home.php"
</script>
<title>Page Redirection</title>
</head>
<body>
<p>If you are not redirected automatically, follow the <a href='/pages/home.php'>link to home page</a></p>
</body>
</html>

index.php is:

<?php
header("location:/pages/home.php");
?>

htaccess has:
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteCond %{HTTP_HOST} ^gatekeeperel.co.uk
RewriteRule (.*) http://www.gatekeeperel.co.uk/$1 [R=301,L]


Any ideas where the fault is there? Can't find anything that makes any sense on internet. Ta.

NickFitz
21st January 2015, 22:15
You've left the actual domain name in the .htaccess code even though you replaced it with mysite.co.uk everywhere else ;)

Not sure where the "double redirect' thing is coming from. I just had a try with an HTTP debugging proxy running. Going to the domain without www resulted in a single "301 Moved Permanently" to www.mysite.co.uk, as expected from the rewrite rules


RewriteCond %{HTTP_HOST} ^mysite.co.uk
RewriteRule (.*) http://www.mysite.co.uk/$1 [R=301,L]


None of the stuff supposedly in index.html or index.php seems to have applied in my case, as there was no further redirect and I got a page showing your products.

Does it refer to any particular URLs in the report? I tried adding something to the basket, which caused an HTTP POST to guides.php, which redirected back to guides.php via a GET - all perfectly normal. Going to checkout caused an HTTP POST to guides.php which redirected to checkout.php - again, all fine.

At no point was I sent to /pages/home.php though, so I'm not sure what that bit's about :confused:

darrylmg
21st January 2015, 23:09
Could it be that RewriteRule for index.html in the .htaccess.
Looks like if it finds you've entered index.html, it just redirects to the root, which on most Web servers is index.html.

mudskipper
22nd January 2015, 07:22
Same as Nick - I get redirected to the www version, but then the page displays correctly.

You haven't got any .htaccess files lurking in subfolders have you?

xoggoth
22nd January 2015, 09:50
Great! Ta for detailed answers. Nice to know most of it works, . Ta for the time spent!


At no point was I sent to /pages/home.php though


Wouldn't now. Been simplifying structure. The subdirectory for the main cart pages was originally so I could I could test it all out while still leaving old shopping cart up. Was working on it yesterday and moved all up to root directory, changed home.php to index.php. Made sure got consistent use of / and no http refs to my own stuff.

This htaccess is a total mystery, so many variations on net. As I now have an index.php in the root directory as far as I can see only redirect I need is to ensure that anyone typing rubbish.co.uk, rubbish.co.uk/index.html, www.rubbish.co.uk/index.php etc etc is shown www.rubbish.co.uk with no specific page names. (Note have a sub domain with index.html and own htaccess, don't want to mess that up). The following sorts the rubbish.co.uk and www.rubbish.co.uk problems:

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

However, tried various things and going to index.php from another page on the site still causes index.php to show in the toolbar. What actually works there?

xoggoth
22nd January 2015, 11:31
This seems to do all I want:

DirectoryIndex index.php
#Force www:
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteCond %{HTTP_HOST} ^gatekeeperel.co.uk [NC]
RewriteRule ^(.*)$ http://www.gatekeeperel.co.uk/$1 [L,R=301,NC]
#avoid explicit index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

HTACCESS seems more complicated than entire programming languages! Gordon Bennet!

NickFitz
22nd January 2015, 13:06
This seems to do all I want:

DirectoryIndex index.php
#Force www:
RewriteEngine On
RewriteRule ^index\.html$ / [R=301,L]
RewriteCond %{HTTP_HOST} ^gatekeeperel.co.uk [NC]
RewriteRule ^(.*)$ http://www.gatekeeperel.co.uk/$1 [L,R=301,NC]
#avoid explicit index.php
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

HTACCESS seems more complicated than entire programming languages! Gordon Bennet!

It sure is :)

xoggoth
22nd January 2015, 13:21
It sure is

Agh! Removed "DirectoryIndex index.php" that was giving me a forbidden error on subdomain. All seems ok now. Ta again for help.