Search code examples
apache.htaccesshttp-redirectmod-alias

301 Remove Entire last Directory from url using htaccess


SCENARIO: Joomla + SH404

A previous version of a component was adding "/registration" to the event page url to redirect it towards the related registration form.

The new version integrates the form in the same event page. The problem is that the Apps still redirects to the previous url and I cannot recode them at this time.

So, I should remove the last part of SEO Url using htaccess

Example: http://mydomain.ext/category/this-is-my-page/registration

should becomes

http://mydomain.ext/category/this-is-my-page

I tried in htaccess:

//301 Redirect Entire Directory
RedirectMatch 301 /registration(.*) /$1

but it redirects to home page

any tips?


Solution

  • This one worked fine for me:

    RewriteRule ^(.*)/registration /$1 [R=301,L]

    thanks to Ellegi