Error 500 when changing .htaccess file on producti

2019-09-19 15:11发布

问题:

I was previously running a .htaccess file on my local development version of my Wordpress site without any issues, but making the equivalent changes to the .htaccess file on my production site results in the entire site returning Error 500s.

The site is structured on the server like so:

- www.mydomain.com
-- logs
-- public_html
--- (Wordpress root folder)
--- .htaccess
--- index.php 
-- webstats

Here is the modified .htaccess file that I'm trying to get running on the site:

#START WORDPRESS

RewriteEngine On
RewriteBase /public_html/

RewriteRule ^about/?$ /public_html/about/history/ [L,NC,R=301]
RewriteRule ^library/?$ /public_html/the-library/gallery/ [L,NC,R=301]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

#END WORDPRESS

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300

My understanding of the .htaccess syntax is very lacking, so I can't be sure what I'm getting wrong in the syntax of the file to cause this issue.

回答1:

Great shout to anubhava on checking the error.log, I did exactly that and found two discrete errors there.

The first one is the one referenced by Andrea:

Invalid command 'php_value', perhaps misspelled or defined by a module not included in the server configuration

I managed to solve this by wrapping the php_value block with <IfModule mod_php.c> and </IfModule>. Note the lack of a version number after mod_php - using mod_php_7 as recommended in many places didn't work for me.

The second error was the following:

RewriteBase: argument is not a valid URL

Because my .htaccess file was located in my document root (which is public_html in the case of Siteground hosting), this only needed to be a /, and this is also all that was needed in the RewriteRules.

My finished .htaccess, with no errors and all redirects working as they should, now looks like this:

<IfModule mod_php.c>

php_value upload_max_filesize 64M
php_value post_max_size 64M
php_value max_execution_time 300
php_value max_input_time 300

</IfModule>

#START WORDPRESS

RewriteEngine On
RewriteBase /

RewriteRule ^about/?$ /about/history/ [L,NC,R=301]
RewriteRule ^the-library/?$ /the-library/gallery/ [L,NC,R=301]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

#END WORDPRESS