Remove last path from url using .htaccess


I need to create a RewriteRule in my .htaccess file that removes Path ("page-2") if it contains at the end of the url. For example:

http://myhost.com/path/page-2

      

should redirect to:

http://myhost.com/path

      

I found a similar solution for SO:

RewriteEngine On

RewriteRule ^([^/.]+)/?$ /$1/page-2/ [L]

      

However, this doesn't work for me. No redirection occurs. Any help?

+3


source to share


1 answer


You should have this rule:



RewriteEngine On

RewriteRule ^(.+?)/page-2/?$ /$1 [L,NC,R=301]

      

+3


source







All Articles