英文:
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&urun_id=$2 [L,QSA]
RewriteRule ^kategori-([0-9a-zA-Z-_]+)-([0-9]+)$ kategori.php?sef=$1&kategori_id=$2 [L,QSA]
RewriteRule ^yazi-([0-9a-zA-Z-_]+)-([0-9]+)$ yazi.php?sef=$1&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
<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
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&urun_id=$2 [L,QSA]
RewriteRule ^kategori-([0-9a-zA-Z-_]+)-([0-9]+)$ kategori.php?sef=$1&kategori_id=$2 [L,QSA]
RewriteRule ^yazi-([0-9a-zA-Z-_]+)-([0-9]+)$ yazi.php?sef=$1&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)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论