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 http://domain.com/sub as where the content you want to load is. And the resulting URL to only shows http://domain.com but still load the content in in the /subfolder. This could be modified many ways to suit the needs for the application at hand.

Leave a Reply

Your email address will not be published. Required fields are marked *