Click here to Skip to main content
15,917,176 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I had some hrefs in a page like this:

<a href="cities/Social Security Lawyer in Ann Arbor">Ann Arbor</a>

I've changed them to this (with hyphens):

<a href="cities/Social-Security-Lawyer-in-Ann-Arbor">Ann Arbor</a>

This is in my htaccess file (the hyphen in the first part is new):
RewriteRule ^cities/([a-zA-Z.\ -]+)/?$ cities.php?city=$1 [NC,L]

Everything works fine in both cases. When my hrefs had the spaces, I got to the correct page and content. After I added the hyphens to the hrefs and added it to the RewriteRule that worked fine also.

The page that's called for all of this is cities.php and of course the query string is the "Social-Security-Lawyer-in-Ann-Arbor" for example.

Now, I need to do something in htaccess so that if the visitor has saved a previous URL without the hyphens, I can redirect them to the correct page/query string with the hyphens.

I tried the following above the other RewriteRule but it doesn't work

RewriteRule ^Social%20Security%20Lawyer%20in%20Ann%20Arbor$  [R=301,L]

Does anyone have any suggestions?

2013-03-04 - This page seems to have the answer but I'm unclear as to how to apply it to my specific situation: Apache .htaccess query string redirects[^]

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900