Forum Topic: WordPress – redirecting posts – default format

Forum: .htaccess Forum : Redirecting • Posted by Anthony Bartoli • Updated:

I cannot redirect WordPress URLs in their default format:

http://www.domain.com/?p=1

None of the following work:

Redirect 301 ?p=1 http://www.domain/correct-permalink/
Redirect 301 /?p=1 http://www.domain/correct-permalink/
Redirect 301 http://www.domain/?p=1 http://www.domain/correct-permalink/

Interestingly, permalink redirects work fine:

Redirect 301 /old-permalink/ http://www.domain.com/correct-permalink/

How do I redirect a URL with just a query string like

http://www.domain.com/?p=1

2 Replies to “WordPress – redirecting posts – …”

Jeff Starr
Posted by Jeff Starr

To get at the query string, use %{QUERY_STRING}, for example:

<IfModule mod_rewrite.c>
	RewriteCond %{QUERY_STRING} ^p\=1$ [NC]
	RewriteRule .* http://www.domain/correct-permalink/? [R=301,L]
</IfModule>

The question mark at the end of the rewrite rule tells Apache to strip the query string from the URL. Note that you may need to fiddle with the regex of the query-string variable, it's off the top of my head and I haven't had any coffee yet.

Posted by Anthony Bartoli •

It works great. Thanks!