Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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.

share|improve this question
add comment

1 Answer 1

up vote 2 down vote accepted

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]
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.