0

So I'm working on a site for a magazine, and I want the URL /latest to rewrite to the file latest.php. I'm working on a cPanel hosting server, so I put a .htaccess in the /public_html directory like so (important line is the 8th):

RewriteEngine On
RewriteRule ^archives/search/?$ /archives/search.php [L]
RewriteRule ^archives/([\d]{4})-([\d]{1})/?$ /archives/download.php?year=$1&issue=$2
RewriteRule ^archives/([\d]{4})/?$ /archives/download.php?year=$1
RewriteRule ^archives - [L]
RewriteRule ^admin - [L]
RewriteRule ^search - [L]
RewriteRule ^latest /latest.php [L]
RewriteRule ^contact/?$ /contact.php [L]
RewriteRule ^([a-z]+)/?$ /page.php?p=$1 [L]

ErrorDocument 404 /notfound.php
ErrorDocument 500 /dberror.php

However, upon navigating to /latest, I get a 500 interal server error. I originally thought it was some problem in the .php file, but that was ruled out when I completely emptied the file latest.php and the error persisted. Interestingly, when I change the /latest to anything else and navigate to that, it works. I have no idea why. I'd like to give the link to the full site, but it's still under development so I am not allowed to.

1 Answer 1

2

Your rewrite rule may be a non-sense to the server:

RewriteRule ^latest /latest.php [L]

Means "if someone wants to access to something that begins with "latest" then go to "/latest.php".

So the scenario is: you try to access to "latest", which is redirected to "/latest.php" then "/latest.php" is redirected to "/latest.php" and so on. It goes to an infinite redirection loop = 500 internal server error.

This rule may be more appropriate:

RewriteRule ^latest(/|)$ /latest.php [L]

Which means: if there either the URL latest or lastest/ then go to /latest.php

By the way I'd suggest to add non case sensitive = NC and query string append QSA to your rewriterule, this would end with something like:

RewriteRule ^latest(/|)$ /latest.php [QSA,NC,L]

Maybe this rule is the same, I didn't test:

RewriteRule ^latest/?$ /latest.php [QSA,NC,L]

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .