Page 3 of 4

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:09 am
by Celauran
Exactly as it should be. So we're entering that final conditional block, meaning the problem lies with the header call.

Code: Select all

if ($product->catid != $urlcatid || $product->subid != $urlsubid)
{
    // header("Location: /product/$product->catid/".urlencode($catname)."/$product->subid/".urlencode($subcatname)."/".urlencode($product->id)."/".urlencode($title)."/", TRUE, 301);
    $location = "/product/$product->catid/".urlencode($catname)."/$product->subid/".urlencode($subcatname)."/".urlencode($product->id)."/".urlencode($title)."/";
    var_dump($location); exit;
}
What now?

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:12 am
by simonmlewis
[text]string(79) "/product/518/CAT-NAMEHERE/344/SUB-NAMEHERE/1919/PRODUCT-TITLEHERE/" [/text]
That produces this, on the page where the URL is wrong.
On the page where the URL is correct, it just loads as it should.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:13 am
by Celauran
Does the string output look like what the URI should be? Does that URI work if you request it directly in your browser?

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:16 am
by simonmlewis
No.
I am putting in a dodgy subid into the URL... that message appears. That message differs from what's in the URL at this point, I suppose because I have commented out the redirection.
So why won't it redirect??

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:18 am
by Celauran
I asked two separate questions. Which one are you replying no to? Does the URI look wrong? Does the new generated URI look right but not respond when you request it?

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:19 am
by simonmlewis
Does the URI look wrong?
The URL is what I typed in. It has not changed. So if I type in the wrong one, the wrong one remains. If I type in the right one, the right one remains.

Does the new generated URI look right but not respond when you request it?
If I type in the wrong one, the new one SHOULD generate - but doesn't. This is the issue if I uncomment the header code.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:23 am
by Celauran
That doesn't make much sense.

So if you request yoursite.co.uk/product/518/CAT-NAMEHERE/344/SUB-NAMEHERE/1919/PRODUCT-TITLEHERE/ the debug text is:
[text]string(79) "/product/518/CAT-NAMEHERE/344/SUB-NAMEHERE/1919/PRODUCT-TITLEHERE/" [/text]

And if you instead request yoursite.co.uk/product/12345/CAT-NAMEHERE/344/SUB-NAMEHERE/1919/PRODUCT-TITLEHERE/ the debug text is:
[text]string(79) "/product/12345/CAT-NAMEHERE/344/SUB-NAMEHERE/1919/PRODUCT-TITLEHERE/" [/text]

Is that what you're saying? It's pulling junk from the database?

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:25 am
by simonmlewis
No.
If I go to the CORRECT URL... (the top one you quote), then the page loads just fine and dandy.
If I put in the bad one, with the 12345, it loads that error message.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:26 am
by Celauran
So far so good. Does the debug message have the correct product ID or does it still contain the incorrect one?

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:29 am
by simonmlewis
If I put in the CORRECT URL into the address bar, everything works as you expect with the product page loading.
If I then change that subid to anything else, the URL remains as typed, and that debug message appears, but it appears with the CORRECT URL in it... ie.. it doesn't show the dodgy subid.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:31 am
by Celauran
simonmlewis wrote:If I put in the CORRECT URL into the address bar, everything works as you expect with the product page loading.
That has always been the case.
simonmlewis wrote:If I then change that subid to anything else, the URL remains as typed
Good. That's expected behaviour right now.
simonmlewis wrote:and that debug message appears, but it appears with the CORRECT URL in it... ie.. it doesn't show the dodgy subid.
Perfect. So the correct URI is being generated and it's the header() call that's failing. Remove the debug bits, restore the header, add an exit after the header call and let's see what happens.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:35 am
by simonmlewis
That's a new one.

I get Firefox's error message:
The page isn't redirecting properly

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

This problem can sometimes be caused by disabling or refusing to accept cookies.
But the URL did change to the new one.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:37 am
by Celauran
With the URL being rewritten correctly, I'd look at your .htaccess rules.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:39 am
by simonmlewis
Ok that was my bad. Maybe you can help there too. I put a / on the end, and in my HTACCESS I don't have one, so that killed it.
If I remove that last slash, it works!!
Page redirects to the new one.

Re: Redirect user via 301 - too many loops?

Posted: Tue Oct 13, 2015 10:39 am
by simonmlewis
Is it because of that missing exit, it wouldn't work before?