Mobile app version of vmapp.org
Login or Join
Sarah324

: 301 redirect to the new website but without apostrophes in the URL 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

@Sarah324

Posted in: #301Redirect #Apache #Htaccess

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/

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Sarah324

1 Comments

Sorted by latest first Latest Oldest Best

 

@Eichhorn148

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 ^(.*)'(.*)$ / [L]
RewriteRule ^(.*)’(.*)$ / [L]

RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule ^(.*)$ http:/newsite.example.com/ [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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme