MoS MoS Tech – Help for Admins Tech Ramblings of MoS and assorted other musings


htaccess rewrite rule to remove a subfolder from a URL

Using .htaccess you can do many things.  This small tidbit will focus on removing and rewriting (mask, hide) the subfolder aspect on a URL to only have the base domain present.  You will want to create a .htaccess file if one is not present already in your public_html (or main doc root) for the site.

nano -w .htaccess

Yes I like nano! got something with it? Ha.  Use whatever you like such as VIM if you prefer.  Next you will add the following text to the file.

RewriteEngine On RewriteRule ^$ sub/ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ sub/$1
This will assume you have as where the content you want to load is. And the resulting URL to only show butstill load the content in in the /sub folder. This could be modified many ways to suit the needs for the application at hand.
Filed under: Tech 23 Comments