Webmasters Stack Exchange is a question and answer site for pro webmasters. 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 want to redirect a request look like




where abc is a fixed directory name and def can be any string.

How can I do this using .htaccess?

share|improve this question
What have you tried? – John Conde Dec 29 '12 at 23:35
You say "redirect", but presumably you mean "internal rewrite"? You want mydomain.com/abc/def to remain in the address bar? – w3dk Dec 30 '12 at 0:40

In .htaccess put:

Options +FollowSymLinks
RewriteEngine on

RewriteCond %{QUERY_STRING} !id=
RewriteRule ^abc/(.+) /abc/index.php?id=$1 [NC,L]

Note that I included a check for the presence of the id query string parameter to prevent the url http://mysite.com/abc/index.php?id=def from being rewritten.

share|improve this answer

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.