我的代码在另一台服务器上运行良好。我只是移动了主机。代码完全相同。我只是将其复制并粘贴到新位置。
使用空白的 htaccess 文件时,我不会给出任何错误。但是如果我输入哪怕一行,例如
RewriteEngine on
我收到 500 错误。
以下是要提到的整个 htaccess 文件
RewriteEngine on
# Forcing HTTPS
RewriteCond %{HTTP_HOST} ^(www\.)(.+) [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?(.+)
RewriteRule ^ https://%2%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_METHOD} !^POST$
# hide .php extension
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R=302,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ profile.php?id=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ profile.php?id=$1&amount=$2 [L]
Options -Indexes
<FilesMatch "\.(?i:gif|jpe?g|png|ico|css|js|swf)$">
<IfModule mod_headers.c>
Header set Cache-Control "max-age=1728000, public, must-revalidate"
</IfModule>
</FilesMatch>