301 Redirect for URL with Special Character

I’ve struggled with this for days now, not being as knowledgeable in htaccess as I would like to be. I would be most grateful for any help offered.

I have a series of URLs that look like this:
/_apps/water_faqs/reviews_details.php/18/what+is+culligan’s+100%25+satisfaction+guarantee/

I need to redirect them to:

http://www.mysite.com/at-home-or-work/water-treatment-faqs/what-is-culligans-100-satisfaction-guarantee.php

Through a lot of searching I finally found I could replace the + sign in the old URL with ([^.%]), using RewriteRule to do the redirecting. That worked with all the other URLs except the one above, which has a special character (%25, the substitution for %) in the middle. I assume that’s what’s throwing everything off, since the apostrophe has converted well in other URLs.

My current effort (not working) looks like this:

RewriteRule ^/_apps/water_faqs/reviews_details.php/18/what([^.%])is([^.%])culligan's([^.%])100%25([^.%])satisfaction([^.%])guarantee/$ http://www.mysite.com/at-home-or-work/water-treatment-faqs/what-is-culligans-100-satisfaction-guarantee.php [NC,L,R=301]

How do I account for that special character in the redirect statement in htaccess? I can’t change it since it was the old URL for the page, but I do need to redirect it.

Thanks in advance for any assistance!

P

I’m assuming 18 is an ID, and so is unique, i.e. this URL is the only URL on your site that starts with /_apps/water_faqs/reviews_details.php/18/ ?

If so, there is no need to match the complete URL. You could also just match /_apps/water_faqs/reviews_details.php/18/ and lose the $ at the end of your regex like so:

RewriteRule ^/_apps/water_faqs/reviews_details.php/18/ http://www.mysite.com/at-home-or-work/water-treatment-faqs/what-is-culligans-100-satisfaction-guarantee.php [NC,L,R=301]

:slight_smile:

You’re quite right, that is a unique ID when I looked at it within the old site files. However, the code as you wrote it does not work either. But at least it’s given me a trail/idea to follow. :slight_smile:

Thank you for your help!

Could you post your complete .htaccess? Maybe there is some other rule interfering with this one.

Also, I just saw you have the [NC] option added to the RewriteRule. Feel free to drop that one, as it has no effect on that particular rule whatsoever, but causes some overhead (so just leave [L,R=301]).

[NC] is typically only used for case insensitive %{HTTP_HOST} comparison, and since an URL typically is case sensitive, [NC] is not needed.

If I use the following:

redirectMatch 301 ^/_apps/water_faqs/reviews_details.php/18/ http://www.mysite.com/at-home-or-work/water-treatment-faqs/what-is-culligans-100-satisfaction-guarantee.php?

… it accomplishes what I want, except it leaves a ? at the end of the URL so the URL looks like this when the user arrives at the new page:

http://www.mysite.com/at-home-or-work/water-treatment-faqs/what-is-culligans-100-satisfaction-guarantee.php?

Otherwise, without the ? in the code, it will take the new URL and tack on “?page=[the_OLD_URL]” as below, replacing the apostrophe and adding in the percent symbol without entity encoding:

http://www.mysite.com/at-home-or-work/water-treatment-faqs/what-is-culligans-100-satisfaction-guarantee.php?page=_apps/water_faqs/reviews_details.php/18/what+is+culligan%27s+100%+satisfaction+guarantee/

From what I understand, “redirectMatch 301” is what is used to redirect a folder to a single page…

Will post the rest of the code if you still need it.

I’d advise you to read that part of the Apache manual again, because what you’re describing is not what it does…

Actually, what I was reading was this:
http://www.squidoo.com/301

I do understand that RedirectMatch makes use of standard regular expressions unlike Redirect, but the URL above and what I have read elsewhere indicated that it was useful for redirecting folders to a single page.

I don’t pretend to be expert or have extensive knowledge of htaccess. That’s why I’m here… to learn.

And thank you for your help, it really did help to put me on a better track with some answers, even if they are not perfect. I just haven’t got to the final solution yet, and greatly appreciate the assistance you’ve given.

P

I justed the following on my server


RedirectMatch 301 ^/_apps/water_faqs/reviews_details.php/18/ http://www.mysite.com/at-home-or-work/water-treatment-faqs/what-is-culligans-100-satisfaction-guarantee.php

So the same you had, but without the trailing ? and it works fine for me. I guess there is something in the .htaccess or in your PHP appending the ?page= stuff.