Lauren Eccles Lauren Eccles - 4 months ago 17
Apache Configuration Question

Remove subfolder from URL if the next subfolder is a specified subfolder (.htaccess)

For example:

This is fine:

http://example.com/ecommerce/


This is also fine:
http://example.com/ecommerce/another-sub/


But if the subfolder after ecommerce is seo, remove ecommerce:

This is not fine:
http://example.com/ecommerce/seo/
and should be redirected to
http://example.com/seo/

Answer

Assuming there is no .htaccess in ecommerce/, you can use this rule in site root .htaccess:

RewriteEngine On

RewriteRule ^ecommerce/(seo)(/.*)?$ /$1$2 [L,NC,R=302]