3

I'm trying to do a rewrite rule on Apache where it rewrites the url to append a query string to the end:

http://example.org/page1.aspx

goes to

http://example.org/page1.aspx?query=12345

Problem is when I apply this rule:

RewriteRule ^\/page1.aspx$ http://example.org.aspx?query12345 [NC,L,R=301]

I end up getting a redirect loop.

Any help would be much appreciated!

1 Answer 1

2

You need to use a condition to check if query string is empty first:

RewriteCond %{QUERY_STRING} ^$
RewriteRule ^/?page1\.aspx$ %{REQUEST_URI}?query=12345 [NC,L,R=301]

Make sure to clear your browser cache before testing this.

Sign up to request clarification or add additional context in comments.

1 Comment

Superb! Thanks a lot for the speedy reply, it works. :)

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.