.htaccess - how to remove the last part of a url?

I want to remove (redirect or replace) the last part of the url.

For example, I want

www.example.com/cocacola/anything 

      

to be

www.example.com/cocacola

      

So

www.example.com/cocacola/123  or www.example.com/cocacola/cat   ...etc 

      

should be

www.example.com/cocacola

      

I tried to figure it out but couldn't find a suitable solution

Here is what I have tried

RewriteRule ^(cocacola)\(.+)$ http://example.com/cocacola [R=301,L,NC]

      

How can I write a .htaccess file to solve the above issue?

+3


source to share


1 answer


This rule can be used in a file DOCUMENT_ROOT/.htaccess

:



RewriteEngine On

RewriteRule ^(cocacola)/.+$ /$1 [L,NC]

      

+1


source







All Articles