Reputation: 1080
So basically i want 2 folders in root one is server and the other is public.
Folder server is secured by always goto server/routes.php
Folder public is free to goto wherever if that file or dir exist.
If URL is localhost/server(anything) it goes to the server/routes.php with the URL (anything)
If URL is localhost/(anything but server) and (anything but server) is not a file or a dir in public it goes to the public/index.html with the URL (anything but server) otherwise if (anything but server) is a file or a dir in public it goes to public/(anything but server) i.e. (a file or a dir)
Some exmaples:
How would I do this logic in .htaccess?
Upvotes: 2
Views: 2238
Reputation: 19528
Place this .hatccess
on the folder server
:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /server/
RewriteRule ^routes\.php$ - [L]
RewriteRule . routes.php [L]
RewriteRule ^$ routes.php [L]
And place this .htaccess
on the root folder of your domain:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{DOCUMENT_ROOT}/public/$1 !-d [NC]
RewriteCond %{DOCUMENT_ROOT}/public/$1 !-f [NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /public/index.html [L]
RewriteCond %{DOCUMENT_ROOT}/public/$1 -d [NC,OR]
RewriteCond %{DOCUMENT_ROOT}/public/$1 -f
RewriteCond %{REQUEST_URI} !^/public/ [NC]
RewriteRule ^(.*)$ /public/$1 [L]
Give this 2 set of .htaccess
a try and keep in mind that if you have tried anything else early using 301 redirects its advisable that you clear your browser cache or use a different browser that you haven't used to browse those sites to avoid the cache.
Upvotes: 4