I will preface this question by saying that I know next to nothing about Apache directives, but I need to use them in my project to hide the contents of the root folder, and also to hide the /public portion of the URL.
httpd.conf
LoadModule rewrite_module lib/httpd/modules/mod_rewrite.so
I know that mod_rewrite is enabled, because I have other .htaccess files in the same project that work just fine. It is just this one file in the root folder that seems to have no effect.
example of a .htaccess file in the /public folder that works
<IfModule mod_rewrite.c>
Options -Multiviews
RewriteEngine On
RewriteBase /php_mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
</IfModule>
.htaccess file that does not work
<IfModule mod_rewrite.c>
RewriteEngine On RewriteRule ^$ public/ [L] RewriteRule (.*) public/$1 [L]
</IfModule>
(update) same .htaccess file as previously, but reformatted
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
Are there any errors in my .htaccess file, or is there something that I have overlooked in my Apache configuration for this to work as intended?
Note that my intention is to redirect the visitor away from the root folder and into the public subfolder, and hide the /public portion of the URL, so that localhost/my_site/public
would become localhost/my_site/
.
I run Apache locally on macOS Monterey with virtual hosts enabled. I do not make use of the default directory, but instead have my project in another location.
httpd.conf
DocumentRoot "/Users/mihkel/Documents/development/www"
<Directory "/Users/mihkel/Documents/development/www">
#
# Possible values for the Options directive are "None", "All",
# or any combination of:
# Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
#
# Note that "MultiViews" must be named *explicitly* --- "Options All"
# doesn't give it to you.
#
# The Options directive is both complicated and important. Please see
# http://httpd.apache.org/docs/2.4/mod/core.html#options
# for more information.
#
Options Indexes FollowSymLinks
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# AllowOverride FileInfo AuthConfig Limit
#
AllowOverride None
#
# Controls who can get stuff from this server.
#
Require all granted
</Directory>