1

I would like to redirect without looking at the query string, and my redirect result no need append the query string as well, so I add a ? at the end of the RewriteRule.

I tried the following syntax, but the outcome just close to it.

RewriteCond %{QUERY_STRING} .* [NC]
RewriteRule ^exd\.asp$ http://www.example.com/index.php?r=p/consumer? [R=301,L]

and also, i tried to escape the first ?, which I need it, but still the same outcome.

RewriteRule ^exd\.asp$ http://www.example.com/index.php\?r=p/consumer? [R=301,L]

Outcome:

http://www.example.com/index.php?r=p/consumer%3f

I want to get ride of the %3f.

Thanks!

1 Answer 1

3

You don't need to append a ? at the end if you already have a query string in your target. Just do this:

RewriteCond %{QUERY_STRING} .* [NC]
RewriteRule ^exd\.asp$ http://www.example.com/index.php?r=p/consumer [R=301,L]

By default, query strings get appended, like this:

RewriteRule ^foo$ /bar [L]

You request /foo?blah and you get /bar?blah

However, if you have a ? in your target, query strings won't get appended unless you have the QSA, so:

RewriteRule ^foo1$ /bar? [L]
RewriteRule ^foo2$ /bar?q=2 [L]

You request /foo1?blah and you get /bar, you request /foo2?blah and you get /bar?q=2. If you include a QSA in the rewrite flags, then &blah gets appended to the end.

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

2 Comments

hi Jon Lin, I actually tried without put a ? at the end, I still get the result example.com/index.php?r=p/consumer%3f , is it anyting wrong in RewriteCond ?
@Shiro there is no way a %3f gets stuck in at the end unless there's another rule that does that or you're browser cache needs to be cleared.

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.