I have the following structure for my website codes at /var/www/html
-- files
---- test.txt
-- app
---- SomePhpCodes.php
---- SomePhpCodes.php
-- public
---- index.php
---- .htaccess
The document root is set to be "/var/www/html/public" but I also want to have files accessible via path "http://mywebsite/files/test.txt".
I think this must be possible using mod_rewrite in the .htaccess
file inside public
but I am struggling to do so.
I tried to add a rule to the default .htaccess
that is provided by the Laravel framework. The current .htaccess
looks like the following:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# The following rule is added by me
RewriteRule files/(.*\.txt) /var/www/html/files/$1 [L]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
The current result is Internal Server Error
when trying to access "http://mywebsite/files/test.txt". I have a feeling I might have missed some settings to make the "files" folder public but I don't have any idea how to do so.
I am stuck and if anyone can help me I will appreciate.