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:




  • No I just tried this:Redirect 301 old/ http:netsite.com/new/
    – dasickle
    Jun 27, 2014 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? Jun 27, 2014 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. Jun 27, 2014 at 16:36

1 Answer 1


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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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