13

I receive 500 internal server error on my website. I think this is because of .htaccess file, but I don't know what's wrong with it.

Server: DirectAdmin, Linux-based

Contents of the .htaccess file is as the following:

# BEGIN All In One WP Security
#AIOWPS_BLOCK_WP_FILE_ACCESS_START
<files license.txt>
order allow,deny
deny from all
</files>
<files wp-config-sample.php>
order allow,deny
deny from all
</files>
<files readme.html>
order allow,deny
deny from all
</files>

#AIOWPS_BLOCK_WP_FILE_ACCESS_END
#AIOWPS_BASIC_HTACCESS_RULES_START
<files .htaccess>
order allow,deny
deny from all
</files>
ServerSignature Off
LimitRequestBody 10240000
<files wp-config.php>
order allow,deny
deny from all
</files>
#AIOWPS_BASIC_HTACCESS_RULES_END
#AIOWPS_PINGBACK_HTACCESS_RULES_START
<IfModule mod_alias.c>
RedirectMatch 403 /(.*)/xmlrpc\.php$
</IfModule>
#AIOWPS_PINGBACK_HTACCESS_RULES_END
#AIOWPS_DISABLE_INDEX_VIEWS_START
Options All -Indexes
#AIOWPS_DISABLE_INDEX_VIEWS_END
#AIOWPS_DISABLE_TRACE_TRACK_START
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
#AIOWPS_DISABLE_TRACE_TRACK_END
#AIOWPS_FIVE_G_BLACKLIST_START
# 5G BLACKLIST/FIREWALL (2013)
# @ http://perishablepress.com/5g-blacklist-2013/

# 5G:[QUERY STRINGS]
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} (\"|%22).*(<|>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (javascript:).*(\;) [NC,OR]
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%3) [NC,OR]
RewriteCond %{QUERY_STRING} (\\|\.\./|`|='$|=%27$) [NC,OR]
RewriteCond %{QUERY_STRING} (\;|'|\"|%22).*(union|select|insert|drop|update|md5|benchmark|or|and|if) [NC,OR]
RewriteCond %{QUERY_STRING} (base64_encode|localhost|mosconfig) [NC,OR]
RewriteCond %{QUERY_STRING} (boot\.ini|echo.*kae|etc/passwd) [NC,OR]
RewriteCond %{QUERY_STRING} (GLOBALS|REQUEST)(=|\[|%) [NC]
RewriteRule .* - [F]
</IfModule>

# 5G:[USER AGENTS]
<IfModule mod_setenvif.c>
# SetEnvIfNoCase User-Agent ^$ keep_out
SetEnvIfNoCase User-Agent (binlar|casper|cmsworldmap|comodo|diavol|dotbot|feedfinder|flicky|ia_archiver|jakarta|kmccrew|nutch|planetwork|purebot|pycurl|skygrid|sucker|turnit|vikspider|zmeu) keep_out
<limit GET POST PUT>
Order Allow,Deny
Allow from all
Deny from env=keep_out
</limit>
</IfModule>

# 5G:[REQUEST STRINGS]
<IfModule mod_alias.c>
RedirectMatch 403 (https?|ftp|php)\://
RedirectMatch 403 /(https?|ima|ucp)/
RedirectMatch 403 /(Permanent|Better)$
RedirectMatch 403 (\=\\\'|\=\\%27|/\\\'/?|\)\.css\()$
RedirectMatch 403 (\,|\)\+|/\,/|\{0\}|\(/\(|\.\.\.|\+\+\+|\||\\\"\\\")
RedirectMatch 403 \.(cgi|asp|aspx|cfg|dll|exe|jsp|mdb|sql|ini|rar)$
RedirectMatch 403 /(contac|fpw|install|pingserver|register)\.php$
RedirectMatch 403 (base64|crossdomain|localhost|wwwroot|e107\_)
RedirectMatch 403 (eval\(|\_vti\_|\(null\)|echo.*kae|config\.xml)
RedirectMatch 403 \.well\-known/host\-meta
RedirectMatch 403 /function\.array\-rand
RedirectMatch 403 \)\;\$\(this\)\.html\(
RedirectMatch 403 proc/self/environ
RedirectMatch 403 msnbot\.htm\)\.\_
RedirectMatch 403 /ref\.outcontrol
RedirectMatch 403 com\_cropimage
RedirectMatch 403 indonesia\.htm
RedirectMatch 403 \{\$itemURL\}
RedirectMatch 403 function\(\)
RedirectMatch 403 labels\.rdf
RedirectMatch 403 /playing.php
RedirectMatch 403 muieblackcat
</IfModule>

# 5G:[REQUEST METHOD]
<ifModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
RewriteRule .* - [F]
</IfModule>

# 5G:[BAD IPS]
<limit GET POST PUT>
Order Allow,Deny
Allow from all
# uncomment/edit/repeat next line to block IPs
# Deny from 123.456.789
</limit>
#AIOWPS_FIVE_G_BLACKLIST_END
#AIOWPS_BLOCK_SPAMBOTS_START
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} ^(.*)?wp-comments-post\.php(.*)$
RewriteCond %{HTTP_REFERER} !^http://(.*)?\.spna\.co\.ir [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule .* http://127.0.0.1 [L]
</IfModule>
#AIOWPS_BLOCK_SPAMBOTS_END
# END All In One WP Security

# BEGIN W3TC Browser Cache
<IfModule mod_deflate.c>
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
</IfModule>
AddOutputFilterByType DEFLATE text/css text/x-component application/x-javascript application/javascript text/javascript text/x-js text/html text/richtext image/svg+xml text/plain text/xsd text/xsl text/xml image/x-icon application/json
<IfModule mod_mime.c>
# DEFLATE by extension
AddOutputFilter DEFLATE js css htm html xml
</IfModule>
</IfModule>
# END W3TC Browser Cache
# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=W3TC_ENC:_gzip]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{REQUEST_URI} \/$
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html%{ENV:W3TC_ENC}" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index.html%{ENV:W3TC_ENC}" [L]
</IfModule>
# END W3TC Page Cache core
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

And here's what the Apache Error Log says:

[Thu Jan 16 00:19:08 2014] [alert] [client 157.55.35.85] /home/sapna/domains/spna.co.ir/public_html/.htaccess: Option All not allowed here

I would be grateful if you help me find out what causes the 500 internal server error.

Thanks.

4
  • 1
    Check your Apache's error.log for the reason of 500
    – anubhava
    Commented Jan 16, 2014 at 9:51
  • Thanks @anubhava for your help. But how should I check this log!? Where is it exactly located? (I'm using DirectAdmin)
    – Omid1989
    Commented Jan 16, 2014 at 10:23
  • That I won't be able to know since every system has different path for error.log. You may need to contact your server admin for this.
    – anubhava
    Commented Jan 16, 2014 at 10:27
  • Thanks again. I found the Apache Error Log which says: "[Thu Jan 16 00:19:08 2014] [alert] [client 157.55.35.85] /home/sapna/domains/spna.co.ir/public_html/.htaccess: Option All not allowed here"
    – Omid1989
    Commented Jan 16, 2014 at 10:49

5 Answers 5

36

Often 500 Internal Server Error happens if you fail to load the mod_rewrite module.

To enable RewriteEngine On you need to run the following command:

sudo a2enmod rewrite
3
  • 1
    Great, thanks for this. I had the same issue with Docker and adding RUN a2enmod rewrite solved the problem for me. Commented May 10, 2017 at 11:05
  • Thank you. Had this issue in the docker. And your solution worked like a charm. Commented Aug 24, 2017 at 3:43
  • Man, you saved me!
    – Asad ullah
    Commented Jun 3, 2020 at 20:59
10

In Local mechine

  1. Create your project folder.

  2. Create .htaccess file in your project root directory like below.

.htaccess

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
  1. Save .htaccess file.
  2. Now click on wamp / lamp / xamp server icon and click on apache and select "rewire_module".

In Cpanel

  1. Directly you need to create .htaccess file with above code and save.

Note: - Please don't write any spelling mistakes in cpanel. If you write any spelling mistakes it will gives you an internal server error (500).

0
8

I was facing same problem, here is solution for ubuntu and apache It was because mod_rewrite module was not enabled, First enable module rewrite:

sudo a2enmod rewrite 

And restart apache

sudo systemctl restart apache2

Now edit for directory level

sudo vim /etc/apache2/sites-enabled/000-default.conf

add these lines at end

<Directory /var/www/html>
    AllowOverride All
 </Directory>

and restart apache again.

sudo service apache2 restart
2
  • 2
    Great, that solved my problem. The module was not enabled Commented Jul 9, 2021 at 13:21
  • 1
    Thanks, it solved my problem too, I was missing the a2enmod rewrite activation in the first place and after activating it, it solved my problem right away.
    – damou_ 1
    Commented Dec 28, 2022 at 12:57
7

Problem is this line due to your Apache cnfig:

Options All -Indexes

change this to:

Options -Indexes
3
  • Thanks @anubhhava for your answer. This worked for me. But what had caused this problem!? And what shall I do to avoid such problems in the future?
    – Omid1989
    Commented Jan 16, 2014 at 10:59
  • You'll need Options All line in your Apache httpd.conf for your site.
    – anubhava
    Commented Jan 16, 2014 at 11:02
  • @anubhava Dear, i am using your answer on my script but i get Internal Server Error in one domain. Can you please check my question for me, please ? stackoverflow.com/questions/55744800/… Commented Apr 18, 2019 at 11:38
1

Make sure you have AllowOverride Options privileges to use Options

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.