Score:1

Enable .htaccess On Ubuntu 20.04 LTS and Apache-2.4.41

pr flag
Ken

I have a problem when moving my website to VULTR VPS - Ubuntu 20.04LTS with Apache - 2.4.41

I'm using Opencart for my website and my problem is whenever I move .htaccess file to the new hosting, the website will display 500 error code.

So I tried to enable rewrite mod.

$ sudo a2enmod rewrite

restart the server

$ sudo systemctl restart apache2

Then I add some code to the following config files /etc/apache2/sites-available/000-default.conf /etc/apache2/sites-enabled/000-default.conf

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

I also change the code of apache2.conf file in /etc/apache2/apache2.conf

From

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

To

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

I also restart the server to make sure it takes effect.

$ sudo systemctl restart apache2

Unfortunately, I got no luck with it. Whenever I move the .HTACCESS file to VULTR. The website still display 500 error code. enter image description here

Here is the code inside my .HTACCESS file.

Options +FollowSymlinks

    # Prevent Directoy listing
    Options -Indexes
    
    # Prevent Direct Access to files
    <FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
     Require all denied
    ## For apache 2.2 and older, replace "Require all denied" with these two lines :
    # Order deny,allow
    # Deny from all
    </FilesMatch>
    
    # SEO URL Settings
    RewriteEngine On
    # If your opencart installation does not run on the main web folder make sure you folder it does run in ie. / becomes /shop/
    
    RewriteBase /
    RewriteEngine On
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
    RewriteRule ^(.*)$ https://www.website.com/$1 [L,R=301]
    RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
    RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
    RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
    RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]

Could you please help me with this issue? I really appreciate your help

in flag
Are you sure the 500 error is the result of `.htaccess` and not something else? There should be a more specific reason for the error located in `/var/log/apache2`. Is the filename in all caps or lowercase?
Ken avatar
pr flag
Ken
This is what I got in /var/log/apache2/error.log. I'm pretty sure 500 error code is caused by .htaccess file ( the .htaccess file in lowercase). If I rename the .htacess to .htacess.txt, I can access the homepage of website. However, without .htacess file, I can't access other pages such as https://www.website/product , https://www.website/category . As I understand, the .htacess file in Opencart will allow me to use friendly url for website.
in flag
The error is pointing to an issue in your mod_security configuration. You may want to check that everything there is properly configured.
Ken avatar
pr flag
Ken
As I find out the mod security may be too strict, I tried to switch OFF security ID 210492 in plesk but again I got no luck. There is no more error code related to ModSecurity. I also turn off the fire wall to see if it can change something, but still got no luck.
MrWhite avatar
es flag
@matigo "The error is pointing to an issue in your mod_security configuration." - Where was this stated?
in flag
@MrWhite looks like the comment containing the error has been deleted.
Score:1
pr flag
Ken

Updated: Problem Solved. The problem occurs because FollowSymlinks not allowed in plesk

So I go to plesk >> website domain >> Apache & Nginx Setting >> disable Restrict the ability to follow symbolic links

MrWhite avatar
es flag
As an alternative to `FollowSymLinks` you may be able to use (the more restrictive) `SymLinksIfOwnerMatch` instead.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.