Forum

Thread tagged as: Error, Configuration

.php redirect problem

Hi,

I've inherited a site build, and I'm looking to start with a bit of housekeeping. I've put the following in the .htaccess file so I can simplify the directory structure and have URLs without the .php extension:

RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.php -f RewriteRule ^(.+)$ $1.php [L,QSA]

... but I'm getting a bit of odd behaviour. If I go to:

/about-footfall ... that works, but...

/about-footfall/ ... returns an error 500.

Also, in the product directory:

/products/ds-65-standard ... behaves similarly to the above, except others don't.

/products/ds-50-eco ... redirects to:

/products/ds-50-eco/ ... and returns an error 500, even though the PHP file is there and the path is set.

Hope that makes sense! Do you have any suggestions? I'm using MAMP Pro on macOS Mojave.

Thanks, Alex

Alex Hardy

Alex Hardy 0 points

  • 2 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You're getting an HTTP 500 status, but that's not the error itself. If you check the MAMP logs you should be able to find the error. What does it say?

I think one of the lines in there that looked like this is the error:

[Thu Dec 20 12:09:43 2018] [error] [client ::1] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

Drew McLellan

Drew McLellan 2638 points
Perch Support

That suggests you have two redirect rules that are redirecting circularly to each other.

Drew McLellan said:

That suggests you have two redirect rules that are redirecting circularly to each other.

How might that be? The rules above are copied from here:

https://docs.grabaperch.com/video/v3/htaccess-rewrites

Could it be something wrong in a page's path? I'm struggling to see why one page would work but another (apparently similarly set up) one wouldn't.

I suspect the answer is staring me in the face :)

Drew McLellan

Drew McLellan 2638 points
Perch Support

Can you post your entire .htaccess file?

No problem, here is everything in it:

RewriteEngine on

# Redirect to PHP if it exists.

# e.g. example.com/foo will display the contents of example.com/foo.php

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME}.php -f

RewriteRule ^(.+)$ $1.php [L,QSA]

Drew McLellan

Drew McLellan 2638 points
Perch Support

Is this at the root level, or are there other things above it in the site structure?

It's at the root level.

Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, then I'm not sure what's going on, but I don't think Perch is doing it.

This occurs if you have echoed anything before deciding to redirect. If so, then the initial (default) headers have been sent and the new headers cannot replace something that's already in the output buffer getting ready to be sent to the browser https://www.mybkexperience.xyz/.

Peter Ray said:

This occurs if you have echoed anything before deciding to redirect. If so, then the initial (default) headers have been sent and the new headers cannot replace something that's already in the output buffer getting ready to be sent to the browser.

If I was redirecting with PHP, yes, but I'm redirecting with .htaccess.

Thanks Drew, I'll see if I can come up with a way around it.

I have been doing it this way for a long time on this server and it just now quit working, thing is I include a header file and the redirect is getting called in the included file so I am not sure how to make it work since the header file is already printed out by the time it reaches my redirect https://prepaidgiftbalance.net/