John R Perry John R Perry - 3 months ago 11
Apache Configuration Question

Is there a generic way to remove a subfolder from a URL regardless of where it's located (.htaccess)

I'm wondering if there is a single method that would remove

sub
from any of these URLs:


  1. http://www.first.com/a/sub/

  2. https://second.org/bob/slob/sub/

  3. http://www.third.me/sub/


Answer

Based on your comment, try the following:

RewriteEngine On

RewriteCond %{REQUEST_URI} ^/(.+)/sub/(.*)$ [NC]
RewriteRule ^ /%1/%2 [R=301,L]
Comments