Remove ‘public’ from url using .htaccess

Remove ‘public’ from URL using .htaccess

If you don’t have SSH access to your server or for any reason you cant configure the domain root to the public directory, the .htaccess can be your ultimate tool to remove public from URL.

On the zCart rood directory create a .htaccess file and add below content:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteCond %{REQUEST_URI} !^/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public/$1
RewriteCond %{HTTP_HOST} ^(www.)?$
RewriteRule ^(/)?$ public/index.php [L]

Now change to on the 2nd and 7th line and save the file.


HELP! A .htaccess.example file is included. Just rename the file to .htaccess and modify it to make it yours.


Was this page helpful?

Leave Comment