I'm new to the whole apache configuration and I have a problem to which I can't seem to find a solution on google.
In short I can't hide folders from URL because it looks as if the document root character (^) starts at the beginning my XAMPP installation folder - /opt/lampp/htdocs/batulabe/
Detailed I've installed a fresh XAMPP VM on my mac without configuring much so everything is basically default. This is the current folder layout for the website:
-batulabe (the document root I intend to make, this folder is inside htdocs)
--public
---pages
----*php pages
--private
---*private, inaccessible files
I'm trying to rewrite URL's like:
http://localhost/batulabe/public/pages/varpage.php
to
http://localhost/batulabe/varpage
result I am getting
http://my_ipv4_address/opt/lampp/htdocs/batulabe/public/pages/public/pages/account.php.php
I have created an extra .conf
file called website.conf
and made Apache read it by writing one line that looks like this - Include "/opt/lampp/apache2/conf/website.conf"
. Other than that, these are the only files (.conf) that I've changed:
-httpd.conf
Alias /bitnami/ "/opt/lampp/apache2/htdocs/"
Alias /bitnami "/opt/lampp/apache2/htdocs"
<Directory "/opt/lampp/apache2/htdocs">
Options Indexes FollowSymLinks
LoadModule rewrite_module modules/mod_rewrite.so
AllowOverride All
Order allow,deny
Allow from all
</Directory>
-website.conf (the same extra configuration file I made for Apache to read)
<Directory "/opt/lampp/htdocs/batulabe">
Options -Indexes
Require all granted
ErrorDocument 403 /batulabe/index.php
</Directory>
<Directory "/opt/lampp/htdocs/batulabe/private">
<LimitExcept POST>
Require all denied
</LimitExcept>
</Directory>
To save time on restarting Apache, my rewrites are temporarily written in .htaccess
(it is stored in "/batulabe" the website root folder). Inside looks like so:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^(.*)$ public/pages/$1.php [R=301,L]
</IfModule>
The flag [R=301]
helped me to see why (probably?) none of the previous rewrite combinations have worked so far, which is because ^
results in http://my_ipv4_address/opt/lampp/htdocs/batulabe/
instead of http://my_ipv4_address/batulabe/
or at the very least without the website folder "/batulabe" since everything is default from installation.
Any help is greatly appreciated!