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

301 Redirect .htaccess not working


Hi guys i need help with 301 redirect using .htaccess

http://www.example.com/dir1/dir2/dir3/11&name=ben

to be redirected to

http://www.example.com/dir1/dir2/dir3/11

So far I have tried this

RewriteRule ^dir1/dir2/dir3/\d+&(.+) /dir1/dir2/dir3/$2 [R=301,L]

it works but redirects me to

www.example.com/dir1/dir2/dir3 without the number(11);

The second one is to redirect (dir/China to dir/china), (dir/London to dir/london) - Uppercase to lowercase

Thanks for your help.


Solution

  • This should work:

    RewriteRule ^(dir1/dir2/dir3/\d+)\&.+$ /$1 [R=301,L,NC]
    

    For lowercase conversion:

    RewriteCond %{REQUEST_URI} [A-Z]
    RewriteRule ^(serviced-apartments/.*)$ ${lc:$1} [R=301,L,NC]
    

    Assuming RewriteMap for lc is correctly defined in Apache config.