Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

I am trying to 301 a page that has a ' in the URL and regular redirect 301 doesn't work. Is there a way to match part of the URL until the ' and use that to 301 to a new page? Example URLs are below:

oldsite.example.com/2011/06/cat-ate-martin’s-homework/

to

newsite.example.com/2011/06/cat-ate-martins-homework/

share|improve this question
    
What have you tried? Have you tried to match URL encoded version of the URL? –  Tero Kilkanen Jun 27 at 16:12
    
No I just tried this:Redirect 301 old/ http:netsite.com/new/ –  dasickle Jun 27 at 16:18
1  
You use two different characters for apostrophes in this post. You ask about straight apostrophes ' but then your example URL has a slanted "smart" apostrophe: . Which do you actually mean? –  Stephen Ostermiller Jun 27 at 16:32
    
I would make a separate script to make these redirections. Making RewriteRules that strip characters from URLs isn't easy in Apache. With the script, you would just pass all requests matching particular directories to the script, which would then return 301 redirect to the users' browser with modified URL. –  Tero Kilkanen Jun 27 at 16:36

1 Answer 1

up vote 3 down vote accepted

Something similar to the rewrite rules from Jon Lin's StackOverflow answer to Remove Characters from URL with htaccess should solve your problem. I would use this which should rewrite the URL to not have the characters, and then redirect:

RewriteRule ^(.*)\'(.*)$ /$1$2 [L]
RewriteRule ^(.*)\’(.*)$ /$1$2 [L]

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(.*)$ http:/newsite.example.com/$1 [L,R=301]

The redirect status lets mod rewrite know that if any of the above rules got applied (thus making the internal redirect status value = 200) then we need to redirect, but we won't reach that part of the rules until it's cleared all of the special character checks.

You'd want these rules all before any of the redirects so that the rules can loop and remove multiple instances of any of those characters. Then, once there are no more special characters, the rewrite engine can trickle down to where your redirects are.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.