Search code examples
.htaccesshttp-redirectdynamic-url

301 Redirect Dynamic URL


OK so I have the following as part of the URL: /user/26872-essi/ and I'm going to final URL of /essi/

I currently have:

Options +FollowSymLinks  
RewriteEngine On
RewriteRule ^user\/([0-9]+)\-.+[/]?$ /user.php?user_id=$1

So I tried:

Options +FollowSymLinks  
RewriteEngine On
RewriteRule ^user\/([0-9]+)\-.+[/]?$ /$2/ [R=301,L]
RewriteRule ^(((?!\.|\/).){1,})\/?$ /user.php?username=$1

It doesn't seem to be passing the variable in. Any ideas what I could be doing wrong?


Solution

  • You may use these rules in your site root .htaccess:

    RewriteEngine On
    
    RewriteRule ^user/\d+-([\w-]+)/?$ /$1/ [R=301,NC,L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\w-]+)/?$ user.php?username=$1 [L,QSA]