3

I want to redirect a request look like

mydomain.com/abc/def

to

mydomain.com/abc/index.php?q=def

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

How can I do this using .htaccess?

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

1 Answer 1

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 that you have read and understand our privacy policy and code of conduct.

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