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?

  • 1
    You say "redirect", but presumably you mean "internal rewrite"? You want mydomain.com/abc/def to remain in the address bar?
    – MrWhite
    Commented Dec 30, 2012 at 0:40

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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