jsquadrilla
jsquadrilla

Reputation: 275

.htaccess redirect with query string

I'm trying to do a very simple redirect. We're moving from a standalone Wordpress install to a Multisite Wordpress install, and I'm trying to get the redirect working for a page with query strings. Here's the code I have so far:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^advise/index_pt(.*)$ http://domain.com/advise/pennies-to-millions/$1 [NE,L,R=301]

Basically, this is what I want: (with or without www)

*.domain.com/advise/index_pt.php?(parameters) => *.domain.com/advise/pennies-to-millions/?(parameters)

Any help is appreciated!

Upvotes: 1

Views: 404

Answers (1)

Jon Lin
Jon Lin

Reputation: 143946

Query strings aren't part of the URI used to match in a RewriteRule directive. So you can't use a regular expression to match against them inside a RewriteRule. If you needed to match against them, you can use a RewriteCond %{QUERY_STRING} <regex> before the rule. However, query strings are automatically appended anyways if you don't create any new ones by using a ? in the rule's target. You can remove all the backreferences in the rule and add parens around the www to make them optional.

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^advise/index_pt.php$ http://domain.com/advise/pennies-to-millions/ [NE,L,R=301]

Upvotes: 2

Related Questions