We are transitioning over to a new forum platform. Please post new issues there. Existing threads will be dealt with here unless you choose to move them over. Visit the new forum

Forum

Thread tagged as: Problem, Error, Blog

.htaccess File Causes Internal Server Error Message

Hello,

I just purchased a license after I successfully set everything up on a local server. I then uploaded Perch to my website and everything worked fine. I wanted to change the URLs of the blog posts. So I opened the .htaccess file that was already on my server and added the rules from this page:

https://docs.grabaperch.com/video/v3/htaccess-rewrites/

When I did so and re-uploaded it, I got a 500 Internal Server Error on every page of my site. I cannot even access Perch dashboard.

I have went through the .htaccess and one by one removed each rule and nothing changed. The only way I can access my site and Perch dashboard in the browser is to completely delete the .htaccess file. What is strange about the situation is that I already had an .htaccess file sitting on my server with the rule to not display the .php extension, and that worked fine.

.htaccess file:

RewriteEngine on
# Redirect to PHP if it exists.
# e.g. example.com/foo will display the contents of example.com/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteRule ^(.+)$ $1.php [L,QSA]

RewriteRule ^blog/([a-zA-Z0-9-/]+)$ /blog/post.php?s=$1 [L]

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
  AddType application/x-httpd-ea-php70___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

Perch diagnostics summary:

Perch: 3.1.2, PHP: 7.0.31, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: b5c5906d452ec590732a93b051f3827e02749b83 $, with PDO Server OS: Linux, litespeed Installed apps: content (3.1.2), assets (3.1.2), categories (3.1.2), perch_blog (5.6.1) App runtimes: <?php $apps_list = [ 'perch_blog' ]; PERCH_LOGINPATH: /perch PERCH_PATH: /home/rrwuxefn/public_html/azureholistic.com/perch PERCH_CORE: /home/rrwuxefn/public_html/azureholistic.com/perch/core PERCH_RESFILEPATH: /home/rrwuxefn/public_html/azureholistic.com/perch/resources Image manipulation: GD PHP limits: Max upload 64M, Max POST 64M, Memory: 256M, Total max file upload: 64M F1: 3b606135b33e6a102526838f4152a807 Resource folder writeable: Yes HTTP_HOST: azureholistic.com DOCUMENT_ROOT: /home/rrwuxefn/public_html/azureholistic.com REQUEST_URI: /perch/core/settings/diagnostics/ SCRIPT_NAME: /perch/core/settings/diagnostics/index.php

Linda Anderson

Linda Anderson 0 points

  • 1 year ago

I isolated it to adding Perch to my site. I deleted the Perch folder (after backing it up) and the site worked fine again with the .htaccess file, minus the rewrite blog rule.

Here is the last error message from my site's error log:

[Sat Sep 01 11:02:24.956586 2018] [core:alert] [pid 1667117:tid 140516507191040] [client 208.68.48.179:61289] /home/rrwuxefn/public_html/azureholistic.com/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by a module not included in the server configuration, referer: http://azureholistic.com/perch/addons/apps/perch_blog/edit/?id=1

Drew McLellan

Drew McLellan 2638 points
Perch Support

Have you checked to see if your hosting has mod_rewrite available?

Hi Drew,

Thanks for your suggestion. My web host does have mod_rewrite turned on by default.

I heard back from my web host this morning, who I also asked to look into the problem last night. I was told there was an unwanted character in front of "RewriteEngine On" in the .htaccess file so they fixed that and now all is working fine. I never saw an unwanted character there, as I checked all three rules multiple times character by character. The only thing I can think of is that I copied the rule straight from this page: https://docs.grabaperch.com/video/v3/htaccess-rewrites/ and looking back at it, there seems to be a space in front of "RewriteEngine On," especially when you highlight it. Maybe I somehow copied and pasted that blank space into my file, but for some reason couldn't see in my text file. As you can see from my initial post above, there is no extra character or space in front of the rule - all I did was select "all," copy, and paste from my .htaccess to show what I had in there. The web host, however, apparently caught it and deleted the unwanted character (the guy said it was a '.') and now it works. I double checked it by downloading it, verifying that all the same rules are there, and re-uploading the file.

It all doesn't make sense, especially since I tried deleting that first rule, and I would still get the error. Oh well, hopefully I won't have any more weird issues like this!

Drew McLellan

Drew McLellan 2638 points
Perch Support

Make sure you have your code editor set to display hidden characters.

Thanks for the tip, Drew! I will definitely check into that.