Barton
Barton

Reputation: 143

Rewriting URL to Query String

I know how to rewrite in the reverse direction and process the Query String, but I need to create one query string parameter based on the tag or category, in lowercase. Therefore, I can user the query string as search parameter in my page:

e.g.

news/tag/Shipping/ ==> http://www.example.com/news/?tag=shipping
news/category/Other/ ==> http://www.example.com/news/?category=other

Tried

RewriteEngine On
RewriteRule ^news/([^/]*)$ /?tag=$1 [L]

Thank you.

Upvotes: 1

Views: 45

Answers (1)

anubhava
anubhava

Reputation: 784998

You need 2 rewrite rules.

RewriteEngine On

RewriteRule ^news/([\w-]+)/?$ news/?tag=$1 [L,QSA,NC]

RewriteRule ^news/([\w-]+)/([\w-]+)/?$ news/?$1=$2 [L,QSA,NC]

Upvotes: 1

Related Questions