Skip to content
Advertisement

After edit of my htaccess file, my website returns 500 internal server error

Before I describe my problem I’d like to let you know in advance that I’ve been searching regarding my problem for few hours already, but nothing has changed so far.

Now as of my problem, I do have a website that uses SSL but people can access it without the certificate, so I wanted to make changes to my htaccess file to force everyone to use SSL.

Originally my file looks like this

<Files 403.shtml>
order allow,deny
allow from all
</Files>
deny from IP
# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php73” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php73 .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit
Options -Indexes

# BEGIN cPanel-generated php ini directives, do not edit
# Manual editing of this file may result in unexpected behavior.
# To make changes to this file, use the cPanel MultiPHP INI Editor (Home >> Software >> MultiPHP INI Editor)
# For more information, read our documentation (https://go.cpanel.net/EA4ModifyINI)
<IfModule php7_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 9M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php73"
   php_value upload_max_filesize 30M
   php_flag zlib.output_compression Off
</IfModule>
<IfModule lsapi_module>
   php_flag display_errors Off
   php_value max_execution_time 30
   php_value max_input_time 60
   php_value max_input_vars 1000
   php_value memory_limit 128M
   php_value post_max_size 9M
   php_value session.gc_maxlifetime 1440
   php_value session.save_path "/var/cpanel/php/sessions/ea-php73"
   php_value upload_max_filesize 30M
   php_flag zlib.output_compression Off
</IfModule>
# END cPanel-generated php ini directives, do not edit

I just changed the file by putting

RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/.well-known/pki-validation/[A-F0-9]{32}.txt(?: Comodo DCV)?$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

And then reuploaded the file, now my website returns 500 Internal Server Error. Even tho if i remove the changes and upload the old one, the problem still remains. When i decided to check the error log, this is what I’m getting

[Fri Dec 27 21:23:26.410830 2019] [core:alert] [pid 29752:tid 47333360273152] [client myIP:28351] /home/root/public_html/.htaccess: </Files> without matching <Files> section, referer: https://mywebsite.com/

I’d appreciate any help.

Advertisement

Answer

Foreword: I used some of my comments to post this as a solution.


It appears that when uploading your file, that the entire file could be in one line and that a # comment character set itself in front of the opening <Files> tag.

Make a copy of your .htaccess and name it to .htaccess_old, then create a new one while making sure that there are newlines (ENTER)’s after each line and making sure nothing is commented out, because that’s what the pound sign is, it’s an .htaccess comment character.

Make sure it’s saved as ANSI and not as UTF-8 and uploaded as TEXT and not BINARY. Saving as UTF-8 could cause it to embed a hidden BOM (byte order mark).

Some FTP programs do not recognize .htaccess files as being a text file and defaults to uploading in BINARY mode; I know this from personal experience. If this is on your own computer, make sure you reboot/restart Apache.

In my experiences with .htaccess files, an 500 error will be thrown if the file was uploaded in BINARY mode instead of TEXT.

You can instruct certain FTP program to upload .htaccess files as TEXT.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement