Vijay
Vijay

Reputation: 5433

htaccess 301 Redirection based on the query string for urls

I've a live url some thing like this,

http://example.com/today.php?year=2012&date=24&mon=07

and i want it to redirected to

http://example.com/holiday-today/year/mon/date

I tried with %{QUERY_STRING} but i dont know how to get three query parameters and pass them to the redirected url.

How can i do this using htacess?

Upvotes: 0

Views: 276

Answers (2)

Jon Lin
Jon Lin

Reputation: 143876

Try adding this in the htaccess file in your document root:

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /today\.php\?year=([0-9]+)&date=([0-9]+)&mon=([0-9]+)
RewriteRule ^today\.php$ /holiday-today/%1/%2/%3? [R=301]

Upvotes: 1

Matty B
Matty B

Reputation: 1058

I would reference these similar questions with great answers:

Query string redirection with htaccess

301 redirect from URL with query string to new domain with different query string

Upvotes: 1

Related Questions