如何在 Linux 本地主机上修复 htaccess 500 错误

huangapple go评论62阅读模式
英文:

How to fix htaccess 500 ERROR on linux localhost

问题

当我使用 sudo a2enmode rewrite 时,模块 rewrite 已经启用。

这是 /etc/apache2/apache2.conf(我删除了 # 行):

# 这是主要的Apache服务器配置文件。它包含了给服务器指令的配置指令。
# 有关指令的详细信息,请参阅 http://httpd.apache.org/docs/2.4/,
# 有关Debian特定提示,请参阅 /usr/share/doc/apache2/README.Debian。

DefaultRuntimeDir ${APACHE_RUN_DIR}

PidFile ${APACHE_PID_FILE}

Timeout 300

KeepAlive On

MaxKeepAliveRequests 100

KeepAliveTimeout 5

User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}

HostnameLookups Off

ErrorLog ${APACHE_LOG_DIR}/error.log

LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Require all denied
</Directory>

<Directory /usr/share>
    AllowOverride All
    Require all granted
</Directory>

<Directory /var/www/>
    Options Indexes FollowSymLinks
    AllowOverride All
    Require all granted
</Directory>

AccessFileName .htaccess

<FilesMatch "^\.ht">
    Require all denied
</FilesMatch>

LogFormat "%v:%p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined
LogFormat "%h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" combined
LogFormat "%h %l %u %t \"%r\" %>s %O" common
LogFormat "%{Referer}i -> %U" referer
LogFormat "%{User-agent}i" agent

IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

这是 .htaccess 代码:

RewriteEngine on

RewriteRule ^sitemap.xml$ sitemap.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^urun-detay-([0-9a-zA-Z-_]+)-([0-9]+)$ urun-detay.php?sef=$1&amp;urun_id=$2 [L,QSA]

RewriteRule ^kategori-([0-9a-zA-Z-_]+)-([0-9]+)$ kategori.php?sef=$1&amp;kategori_id=$2 [L,QSA]

RewriteRule ^yazi-([0-9a-zA-Z-_]+)-([0-9]+)$ yazi.php?sef=$1&amp;blog_id=$2 [L,QSA]
英文:

When i use sudo a2enmode rewrite Module rewrite already enabled.

this is /etc/apache2/apache2.conf (i deleted # lines)

# This is the main Apache server configuration file.  It contains the
# configuration directives that give the server its instructions.
# See http://httpd.apache.org/docs/2.4/ for detailed information about
# the directives and /usr/share/doc/apache2/README.Debian about Debian specific
# hints.



DefaultRuntimeDir ${APACHE_RUN_DIR}


PidFile ${APACHE_PID_FILE}


Timeout 300


KeepAlive On


MaxKeepAliveRequests 100


KeepAliveTimeout 5


User ${APACHE_RUN_USER}
Group ${APACHE_RUN_GROUP}


HostnameLookups Off


ErrorLog ${APACHE_LOG_DIR}/error.log


LogLevel warn

IncludeOptional mods-enabled/*.load
IncludeOptional mods-enabled/*.conf

Include ports.conf

&lt;Directory /&gt;
	Options FollowSymLinks
	AllowOverride All
	Require all denied
&lt;/Directory&gt;

&lt;Directory /usr/share&gt;
	AllowOverride All
	Require all granted
&lt;/Directory&gt;

&lt;Directory /var/www/&gt;
	Options Indexes FollowSymLinks
	AllowOverride All
	Require all granted
&lt;/Directory&gt;






AccessFileName .htaccess


&lt;FilesMatch &quot;^\.ht&quot;&gt;
	Require all denied
&lt;/FilesMatch&gt;


LogFormat &quot;%v:%p %h %l %u %t \&quot;%r\&quot; %&gt;s %O \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; vhost_combined
LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %&gt;s %O \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; combined
LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %&gt;s %O&quot; common
LogFormat &quot;%{Referer}i -&gt; %U&quot; referer
LogFormat &quot;%{User-agent}i&quot; agent


IncludeOptional conf-enabled/*.conf

IncludeOptional sites-enabled/*.conf

this is .htaccess codes;

RewriteEngine on

RewriteRule ^sitemap.xml$ sitemap.php [NC,L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

RewriteRule ^urun-detay-([0-9a-zA-Z-_]+)-([0-9]+)$  urun-detay.php?sef=$1&amp;urun_id=$2 [L,QSA]

RewriteRule ^kategori-([0-9a-zA-Z-_]+)-([0-9]+)$  kategori.php?sef=$1&amp;kategori_id=$2 [L,QSA]

RewriteRule ^yazi-([0-9a-zA-Z-_]+)-([0-9]+)$  yazi.php?sef=$1&amp;blog_id=$2 [L,QSA]

I changed allowoverride None to All, and i enabled rewrite module...

答案1

得分: 1

我用Notepad++编辑了.htaccess文件,第一行有一个字符,当我删除它并保存后,问题得以解决。(在PhpStorm或其他编辑器中未显示)

英文:

I edited the .htaccess file with notepad++ and there was a character in the first line, and when I deleted it and saved, it was fixed. (didn't show up in phpstorm or other editors)

huangapple
  • 本文由 发表于 2023年2月10日 04:01:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/75403851.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定