Search code examples
regex.htaccessmod-rewritehttp-redirecthttp-status-code-301

htaccess 301 redirects with email inside url


I have following type of url that has been reported by Google as 401

http://example.com/products/name/product-name/[email protected]
http://example.com/product-name.php%5C%22
http://example.com/career/%7Bjoblink%7D

how do I 301 these urls using htaccess? What I tried is as follow but didnt worked:

RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^products\/name\/product\-name\/support\@email\.com$ "http\:\/\/www\.exmaple\.com\/products\.php" [R=301,L]

does those special characters such as @ requires different approach?

Thanks!


Solution

  • You can use this rule with B flag in your /blog/.htaccess file:

    RewriteEngine On
    RewriteBase /blog/
    
    RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
    RewriteRule ^2010/01/drying-glass-washing/doug@ 2010/01/drying-glass-washing/ [R=301,L,B,NC]
    

    For rest of 2 URLs have these 2 rules in root .htaccess:

    RewriteRule ^(product-name.php).+ /$1 [R=301,L,NC]
    
    RewriteRule ^(career/)[^\w-] /$1 [R=301,L,NC]