首页 > 解决方案 > 获取 500 Internal Server Error 而不是 404 Not Found 错误

问题描述

因此,当我测试托管在 Bluehost 上的网站时,我想测试运行良好的 404.html。但是,然后我注意到当我输入类似这样的内容时,我不断从 Bluehost 收到默认的 500 内部服务器错误,https://www.example.com/folder/webpage/awdawdasd(基本上在网页名称后加上一个斜杠并输入随机的东西)。在我的 htaccess 中,我这样做是为了让用户访问网站时无需在后面加上 .html,即隐藏 URL 中的扩展名。我该如何解决它,以便当用户在 html 页面之后键入随机内容时,如示例中所示?

请注意,我只使用 Bluehost 的文件管理器,即在 Bluehost 上托管我自己的 html 页面,这些页面是我在作业中编写的,我没有使用 Wordpress 或任何东西。

这是我的htaccess代码,

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php74” package as the default “PHP” programming language.

<IfModule mime_module>
  AddHandler application/x-httpd-ea-php74 .php .php7 .phtml
  
  # Prevent user from going to the website's index
  Options -Indexes

</IfModule>

## EXPIRES HEADER CACHING ##
<IfModule mod_expires.c>
  ExpiresActive On

 # Images
  ExpiresByType image/jpeg "access plus 1 year"
  ExpiresByType image/gif "access plus 1 year"
  ExpiresByType image/png "access plus 1 year"
  ExpiresByType image/webp "access plus 1 year"
  ExpiresByType image/svg+xml "access plus 1 year"
  ExpiresByType image/x-icon "access plus 1 year"

  # Video
  ExpiresByType video/webm "access plus 1 year"
  ExpiresByType video/mp4 "access plus 1 year"
  ExpiresByType video/mpeg "access plus 1 year"

  # Fonts
  ExpiresByType font/ttf "access plus 1 year"
  ExpiresByType font/otf "access plus 1 year"
  ExpiresByType font/woff "access plus 1 year"
  ExpiresByType font/woff2 "access plus 1 year"
  ExpiresByType application/font-woff "access plus 1 year"

  # CSS, JavaScript
  ExpiresByType text/css "access plus 1 month"
  ExpiresByType text/javascript "access plus 1 month"
  ExpiresByType application/javascript "access plus 1 month"

  # Others
  ExpiresByType application/pdf "access plus 1 month"
  ExpiresByType image/vnd.microsoft.icon "access plus 1 year"
  
</IfModule>

## REWRITE RULES
<IfModule mod_rewrite.c>
  RewriteEngine On
  
  # Redirects user from http to https
  RewriteCond %{SERVER_PORT} 80
  RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
  
  # Allow browsers to access webpages without .html at the end
  RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC]
  RewriteRule ^ /%1 [NC,L,R]

  # Redirect user to webpage url without .html if they typed .html in the url
  RewriteCond %{REQUEST_FILENAME}.html -f
  RewriteRule ^ %{REQUEST_URI}.html [NC,L]
  
  # Removes .php extension
  RewriteCond %{THE_REQUEST} /([^.]+)\.php [NC]
  RewriteRule ^ /%1 [NC,L,R]

  # Redirect user to webpage url without .php if they typed .php in the url
  RewriteCond %{REQUEST_FILENAME}.php -f
  RewriteRule ^ %{REQUEST_URI}.php [NC,L]
  
  # Redirect users to the error webpages if user receives a 404 error, etc.
  ErrorDocument 401 /errorpages/401
  ErrorDocument 403 /errorpages/403
  ErrorDocument 404 /errorpages/404
  ErrorDocument 500 /errorpages/500
  ErrorDocument 502 /errorpages/502
  ErrorDocument 503 /errorpages/503
  
  # End of Apache Rewrite Rules
</IfModule>

# php -- END cPanel-generated handler, do not edit

Bluehost 500 内部服务器错误消息图像

编辑:我已经联系了 Bluehost 并且能够推断出它不是来自他们的一方,但问题在于上面的代码。如果用户在后面输入 .html,我还编辑了 apache 重写代码以重定向用户。

更新:设法找到错误日志,它说

/home2/otakuabr/public_html/.htaccess: RewriteRule: bad flag delimiters

标签: .htaccess

解决方案


推荐阅读