在生产服务器上更改.htaccess文件时出现错误500 [英] Error 500 when changing .htaccess file on production server

查看:65
本文介绍了在生产服务器上更改.htaccess文件时出现错误500的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以前在我的Wordpress网站的本地开发版本上运行了 .htaccess 文件,没有任何问题,但是对做了相同的更改我的生产站点上的.htaccess 文件导致整个站点返回错误500。

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

这是修改后的 .htaccess 文件:

#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

我对.htaccess语法的理解非常缺乏,所以我不能确定自己文件语法出错导致此问题。

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.

推荐答案

anubhava 确实做到了,并在那里发现了两个离散错误。

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

第一个是 Andrea 引用的那个:


无效的命令 php_value,可能是服务器配置中未包含的模块
拼写错误或定义了

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

我设法通过用包裹 php_value 块来解决这个问题; IfModule mod_php.c> < / IfModule> 。请注意,在 mod_php 之后缺少版本号-在许多地方建议使用 mod_php_7 对我不起作用。

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.

第二个错误如下:


RewriteBase:参数不是有效URL

RewriteBase: argument is not a valid URL

因为我的.htaccess文件位于我的文档根目录(即 public_html (对于Siteground托管),这只需要是 / ,这也是RewriteRules中所需要的。

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.

我完成的 .htaccess ,没有错误,所有重定向都按预期进行,现在看起来像这样:

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

这篇关于在生产服务器上更改.htaccess文件时出现错误500的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆