1

How do I use the rewrite rule to replace the .php wth /

For example:

search.php?k=background to search/?k=background

What I have so far is:

RewriteRule ^search/?k=([a-zA-Z0-9_-]+)$ search.php/?k=$1

3 Answers 3

2

Here is another option:

RewriteEngine On
RewriteBase / 
#Rule applies only when the script is search.php
RewriteCond %{REQUEST_URI} ^.*search\.php.*$
#Query will be automatically appended to search/
RewriteRule .* http://mydomain.com/search/ [L]

Will redirect:

http://mydomain.com/search.php?k=background to

http://mydomain.com/search/?k=background

1

You need to remove the query string from your rewrite rule, that gets appended automatically:

RewriteRule ^search/?$ search.php [L]
0
1

Try this:

RewriteRule ^(.*)\.php(.*)$ $1/$2
1
  • Thanks for the answer. But the thing is, it should rewrite only for the search.php not for all. Moreover the above example doesn't work.
    – slownage
    Commented Dec 9, 2012 at 22:33

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