slownage
slownage

Reputation: 154

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

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

Upvotes: 1

Views: 77

Answers (3)

Felipe Alameda A
Felipe Alameda A

Reputation: 11809

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

Upvotes: 2

Jon Lin
Jon Lin

Reputation: 143906

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

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

Upvotes: 1

Bohemian
Bohemian

Reputation: 425073

Try this:

RewriteRule ^(.*)\.php(.*)$ $1/$2

Upvotes: 1

Related Questions