Debian 11 and Apache2 - .htaccess not working

Viewed 182

I have a problem. I have an VPS with Debian 11 and Webmin and I want to host my Laravel project, but i need to redirect all requests to public/index.php file but... my .htaccess didn't work.

My .htaccess file

<IfModule mod_rewrite.c>

   RewriteEngine On

   RewriteCond %{REQUEST_FILENAME}  -f [OR]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ public/index.php [L,QSA]

</IfModule>

I tried also

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}  -f [OR]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ public/index.php [L,QSA]

My domain.conf file

<VirtualHost *:80>

    ServerAdmin admin@api.domain.pl
    ServerName api.domain.pl
    ServerAlias www.api.domain.pl

    DocumentRoot /var/www/api.domain.pl/public_html

    <Directory /var/www/api.domain.pl/public_html>
       Options Indexes FollowSymlinks
       AllowOverride All
       Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

RewriteEngine on
RewriteCond %{SERVER_NAME} =www.api.domain.pl [OR]
RewriteCond %{SERVER_NAME} =api.domain.pl
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>

My apache2.conf file

<Directory /var/www>
        Options FollowSymLinks
        AllowOverride All
</Directory>

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory

I have used commands

a2enmod rewrite
service apache2 restart
service apache2 --full-restart

And I see
Screen

Apache2 version: 2.4.54 PHP version: 8.1.8

1 Answers

Are you sure you have him ?

Check if you got it right:

cat /etc/apache2/mods-available/rewrite.load

Activate him with sudo :

sudo a2enmod rewrite

Then restart apache2

sudo service apache2 restart
Related