eepgmja
eepgmja

Reputation: 41

htaccess manipulate query string

I'm trying to write htaccess rule to convert URLs of the following form:

http://example.com/PageViewer.aspx?id=348

to:

http://example.com/?page_id=15348

the number 15 is constant and is followed by the value of id in the original URL.

I tried the following rule:

RewriteCond %{QUERY_STRING} ^(.*)\id=(.*)$
RewriteRule ^(.*)PageViewer\.aspx$ $1?%1page_id=15%2 

however, the result I get is this:

http://example.com/page_id=15348/?id=348

Why is the question mark used in the rule missing? and why is the query string showing at the end of the resulted URL? I don't fully understand the htaccess rewrite rule...

Upvotes: 0

Views: 66

Answers (1)

eepgmja
eepgmja

Reputation: 41

It is solved by using [NE] flag

RewriteCond %{QUERY_STRING} ^(.*)\id=(.*)$
RewriteRule ^(.*)PageViewer\.aspx$ $1?%1page_id=15%2 [NE]

Upvotes: 1

Related Questions