0

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...

1 Answer 1

1

It is solved by using [NE] flag

RewriteCond %{QUERY_STRING} ^(.*)\id=(.*)$
RewriteRule ^(.*)PageViewer\.aspx$ $1?%1page_id=15%2 [NE]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.