Apache 301 Redirects where original URL contains special characters

I’m looking for some .htaccess Redirect or RewriteRule assistance.

My client has a site that use to have poorly formatted URLs that are being reported by Google Web Tools as 404 errors, for example:

/calendar-of-events/wanda-hollberg’s-fused-glass-jewelry-trunk-show/

Notice the bad apostrophe, ” ’ ” character?


Here’s another example:

/dining club.cfm

Notice the space, ” “?


One more example:

/calendar-of-events/“a-viticultural-voyage”-wine-dinnerstar/

Notice the bad quotes, ” “ ” and ” ” “?


I’ve tried redirect rules with no success, such as UTF-8 encoding…

Redirect 301 /calendar-of-events/wanda-hollberg%E2%80%99s-fused-glass-jewelry-trunk-show/ /calendar-of-events/
Redirect 301 /dining%20club.cfm /cuisine/
Redirect 301 /calendar-of-events/%E2%80%9Ca-viticultural-voyage%E2%80%9D-wine-dinnerstar/ /calendar-of-events/

As well as trying to use RegExp…

Redirect 301 /calendar-of-events/wanda-hollberg(.*)s-fused-glass-jewelry-trunk-show/ /calendar-of-events/
Redirect 301 /dining(.*)club.cfm /cuisine/
Redirect 301 /calendar-of-events/(.*)a-viticultural-voyage(.*)-wine-dinnerstar/ /calendar-of-events/

But I’m guessing RegExp doesn’t work in Redirects?!

So I tried a RewriteRule, and still no success…

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule (.*)/calendar-of-events/wanda-hollberg(.*)s-fused-glass-jewelry-trunk-show/$ /calendar-of-events/ [R=301,L]
</IfModule>

Please advise, what am I missing or doing wrong?

Should I use a Redirect or RewriteRule? And how should I write out the rule?


I should also note that this is now on a WordPress site thus the .htaccess file also has…

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

# redirect none-www to www
RewriteCond %{HTTP_HOST} ^domain.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

# redirect m. to www
RewriteCond %{HTTP_HOST} ^m.domain.com$
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

# redirect legacy. to www
RewriteCond %{HTTP_HOST} ^legacy.domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]

</IfModule>

Thank you very much in advance for your suggestions and effort. Cheers.


Source: .htaccess

Leave a Reply