0

I've researched this for awhile now and swear my solution should work according to the following (and hundreds of others here so forgive my duplication):

Example 1 Example 2

I need to remove the query string from a redirect. Old WordPress ?p=### to a new domain/url.

Old Url: blog.domain.com/blog/?p=123
New Url: www.domain.com/yada/woohoo/

With this:

RewriteCond %{QUERY_STRING} ^p=123$
RewriteRule ^/blog/$ http://www.domain.com/yada/woohoo/?  [L,R=301]

I get: http://www.domain.com/yada/woohoo/?p=123

I want: http://www.domain.com/yada/woohoo/

blog.domain.com will be redirected at the DNS level.

What am I missing? The "?" at the end of the rewrite line should remove the query string?

Community
  • 1
  • 1
roadsunknown
  • 3,190
  • 6
  • 30
  • 36

1 Answers1

1

I just tried your code, the only thing i changed was the first / in blog, and i got it working perfectly, without the querystring
If you're running Apache > 2.4 then you can use the flag QSD, but otherwise, with the ? at the end it works. Is there any other rules there?

RewriteCond %{QUERY_STRING} ^p=123$
RewriteRule ^blog/$ http://www.domain.com/yada/woohoo/?  [L,R=301]
doterobcn
  • 307
  • 1
  • 4
  • 15
  • That extra / I had made the difference. All works now. Thanks! – roadsunknown Oct 11 '12 at 14:41
  • On further examination. This works for www.domain.com/blog/?p=123 but not for blog.domain.com/blog/?p=123. Using the subdomain returns the same result as before: www.domain.com/yada/woohoo/?p=123. – roadsunknown Oct 24 '12 at 18:48