Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an htaccess file in my main directory which redirects all top-level directories to a PHP file.

-> /Loch would go to /profile.php?username=Loch

But I also have a subdirectory, lets call it test

I need a rule in test that says, "any sub paths of my directory are actually GET variables.

For example, linking to /test/hello/hi

Should actually go to /test/receiver.php?dataset=hello&action=hi

However, when I use the following rules within an htaccess file in the /test/ directory, it doesn't work this way (I get a 500 error).

RewriteBase /

RewriteEngine On
RewriteRule ^(.*?)/(.*?)/?$ /receiver.php?dataset=$1&action=$2
RewriteRule ^(.*?)/?$ /receiver.php?dataset=$1

I hope I've provided enough info, please help! Thank you.

share|improve this question
up vote 2 down vote accepted

Your regular expressions are not valid. * and ? are both quantifiers which apply to the previous character, and so *? doesn't make sense. You probably want this:

RewriteRule ^(.+)/(.+)/?$ /receiver.php?dataset=$1&action=$2
RewriteRule ^(.+)/?$ /receiver.php?dataset=$1
share|improve this answer
Thank you very much. Would upvote but I don't have enough points! – iLoch Aug 24 '12 at 9:04

Your Answer


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.