bort
bort

Reputation: 359

Wildcard redirect at end of url in .htaccess

I couldn't find an accurate solution for this on SO.

I have a Wordpress site that needs any URL that contains /blog/?p* to redirect to /blog

The * denotes the wildcard point. So any URL that starts with /blog/?p gets redirected.

I've tried:

RewriteRule ^/blog/?p.*$ http://website.com/blog

But that didn't work.

Upvotes: 0

Views: 638

Answers (1)

jcaron
jcaron

Reputation: 17710

The pattern (the first argument of RewriteRule) only matches the part before the ? (the path). To match the part after the ? (the query string), you need to use a RewriteCond with %{QUERY_STRING}.

So for instance:

RewriteCond %{QUERY_STRING} ^p
RewriteRule ^/?blog/ http://target

Upvotes: 1

Related Questions