2

I am in the middle of changing our site URL structure from this site.com/?team=john-doe to site.com/attorney/john-doe. I have the typical WordPress Htaccess rewrite rules in the htaccess file but what I'm having trouble is we have multiple attorneys that have the ?team=followed by the name. I am trying to do one rule to redirect all with the name being a variable - if that makes sense.

site.com/?team=jane-doe
site.com/?team=nic-cage

Below I commented out a method but when I tried it I got 500 Internal Server error:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

#RewriteCond %{REQUEST_URI} ^/$
#RewriteCond %{QUERY_STRING} ^?team=([x]*)$
#RewriteRule ^(.*) site.com/attorneys/$1 [R=302,L]
</IfModule>

# END WordPress

I also applied this regex:

RedirectMatch 301 ^/?team=(.*)$ site.com/attorneys/$1

Regex is pretty confusing, sorry if I'm not making any sense. I can try and clarify if needed.

0

3 Answers 3

1

RedirectMatch only works for uris .you can't access querystring using this directive. You can use the following RewriteRule , add this before your wordpress rules :

RewriteEngine on

RewriteCond %{QUERY_STRING} ^team=(.+)$
RewriteRule ^ http://example.com/attorneys/%1? [L,R]
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks - I will give this a shot after business hours. Will report back!
0

I am not so much sure but can you try this
RewriteRule ^/?team=(.*)$ http://Yoursitename/attorneys/$1 [R=301,L]

2 Comments

Thanks - I will give this a shot after business hours. Will report back!
Hi @Ankit Prajapati the final solution was RewriteCond %{QUERY_STRING} ^team=(.*)$ RewriteRule ^(.*) https://www.andrewsmyers.com/attorneys/%1? [R=301,L]
0

This is just a guess, but I think the leading question mark ? in

RewriteCond %{QUERY_STRING} ^?team=([x]*)$

is the reason for the 500 server error, because ? is a special character.

? means the preceding element is optional, but since there is no preceding element in ^?team=, this is an error. If you want to match a literal question mark, you must escape it with a backslash \?.

Although, in this case (QUERY_STRING), this is not necessary, because QUERY_STRING does not contain the leading question mark, just the query string itself. This means checking for team=(.*) would be sufficient

RewriteCond %{QUERY_STRING} ^team=(.*)$

There are additional issues with the rule

  • RewriteCond %{REQUEST_URI} ^/$ will match only the home page, nothing else
  • RewriteRule ^(.*) site.com/attorneys/$1 [R=302,L] will not redirect to site.com, because it is missing http://
  • and finally, the back-reference for matches in RewriteCond is %1 instead of $1

2 Comments

Thanks for your descriptive response. So I updated my rules to what you have suggested and it's currently appending ?team=john-doe to the new destination URL. Ex., http://www.example.com/attorneys/?team=john-doe
Yes, I missed that. My answer just explains, why you get a 500 error. But @starkeen already solved this problem with his answer by adding a question mark to the target. This prevents, that the previous query string is added to the new target.

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.