I’ve been searching for 2 days now and haven’t found a complete solution to this problem.
my directories (on localhost):
root
– fons (here is my htaccess file located)
– – functions (some functions)
– – web (index.php)
– – docs (index.php)
– – user (index.php)
I’d like to have when i go to localhost/fons/ , that i see the content of the web map but the url should remain localhost/fons. If i go to localhost/fons/docs/ then i see the docs content , and localhost/fons/user/ -> user content
the .htaccess i’ve written:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(fons/user|fons/docs)
RewriteRule ^$ /fons/web
With this htaccess when i go to localhost/fons/ i get redirected to the web-subfolder and the url changes.
What do i have to change so that the url stays the same, but i see the content of the web folder?
and if possible, is there a way to ditch the ‘fons’ in htaccess, so in the future when i create another project with the same structure, i can just copy paste the htaccess and don’t need to change it?
You should be able to use RewriteBase to eliminate /fons like so:
Also from experience, the rewriterule shouldn’t actually forwarded to the new url in the browser url bar unless you have a [R] flag set. I added the [NC] (case insensitive flag) to explicitly state no [R] flag. If it’s doing it, can you provide a link to test further?