AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 1002059
Accepted
Elmond
Elmond
Asked: 2020-02-07 07:11:29 +0800 CST2020-02-07 07:11:29 +0800 CST 2020-02-07 07:11:29 +0800 CST

已解决 - 500 内部服务器错误 Apache,htaccess 重定向

  • 772

因此,当我访问主域 www 上不存在的页面时,我只会收到正常的 404 错误,但是当我在 dsfds.test.com 之类的子域上访问它时,我会收到错误 500,并且在日志中我拥有这个:

[Thu Feb 06 15:46:41.935207 2020] [core:error] [pid 4744] [client 162.158.154.254:32186] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.

这是我的 htaccess:

#    Mod_security can interfere with uploading of content such as attachments. If you
#    cannot attach files, remove the "#" from the lines below.
#<IfModule mod_security.c>
#    SecFilterEngine Off
#    SecFilterScanPOST Off
#</IfModule>

ErrorDocument 401 default
ErrorDocument 403 default
ErrorDocument 404 default
ErrorDocument 500 default

<IfModule mod_rewrite.c>
RewriteEngine On

#    If you are having problems with the rewrite rules, remove the "#" from the
#    line that begins "RewriteBase" below. You will also have to change the path
#    of the rewrite to reflect the path to your XenForo installation.
#RewriteBase /xenforo

#    This line may be needed to enable WebDAV editing with PHP as a CGI.
#RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


RewriteCond %{HTTP_HOST} ^alphanetworkmc\.com$
RewriteCond %{REQUEST_URI} !^/anm
RewriteRule ^(.*)$ /anm/$1 [L] 

RewriteCond %{HTTP_HOST} ^www\.alphanetworkmc\.com$
RewriteCond %{REQUEST_URI} !^/anm
RewriteRule ^(.*)$ /anm/$1 [L] 

RewriteCond %{HTTP_HOST} ^analytics\.indst\.eu$
RewriteCond %{REQUEST_URI} !^/sa
RewriteRule ^(.*)$ /sa/$1 [L] 

RewriteRule ^favicon.ico favicon.ico [L]

RewriteCond %{HTTP_HOST} ^mail\.indst\.eu$
RewriteCond %{REQUEST_URI} !^/mail
RewriteRule ^(.*)$ /mail/$1 [L] 

RewriteCond %{HTTP_HOST} ^entertainment\.indst\.eu$
RewriteCond %{REQUEST_URI} !^/ent
RewriteRule ^(.*)$ /ent/$1 [L] 

RewriteCond %{HTTP_HOST} ^www\.statesanalytics\.com$
RewriteCond %{REQUEST_URI} !^/sa
RewriteRule ^(.*)$ /sa/$1 [L] 

RewriteCond %{HTTP_HOST} ^statesanalytics\.com$
RewriteCond %{REQUEST_URI} !^/sa
RewriteRule ^(.*)$ /sa/$1 [L] 

RewriteCond %{HTTP_HOST} ^recover\.indst\.eu$
RewriteCond %{REQUEST_URI} !^/mail/admin/
RewriteRule ^(.*)$ /mail/admin/$1 [L] 

RewriteCond %{HTTP_HOST} ^adminmail\.indst\.eu$
RewriteCond %{REQUEST_URI} !^/mail/admin/
RewriteRule ^(.*)$ /mail/admin/$1 [L] 

<If "req('Host') == 'recover.indst.eu'">
RedirectMatch 301 ^/mail/admin/users/login\.php$ /users/password-recover.php
RedirectMatch 301 ^/mail/admin/login\.php$ /users/password-recover.php
</if>

RewriteCond %{HTTP_HOST} mailrules\.indst\.eu$
RewriteRule ^(.*)$ https://www.alphanetworkmc.com/threads/e-mail-tos.21/$1 [L,R=301]


RewriteCond %{HTTP_HOST} ^mail\.alphanetworkmc\.com$
RewriteCond %{REQUEST_URI} !^/mail
RewriteRule ^(.*)$ /mail/$1 [L] 

RewriteCond %{HTTP_HOST} ^mail\.alphanetworkmc\.com [NC]
RewriteRule ^(.*)$ https://mail.indst.eu/$1 [R,L]

RewriteCond %{HTTP_HOST} ^bans\.alphanetworkmc\.com$
RewriteCond %{REQUEST_URI} !^/anm/bans
RewriteRule ^(.*)$ /anm/bans/$1 [L] 

RewriteCond %{HTTP_HOST} ^recover\.alphanetworkmc\.com$
RewriteCond %{REQUEST_URI} !^/mail/admin/
RewriteRule ^(.*)$ /mail/admin/$1 [L] 

RewriteCond %{HTTP_HOST} ^recover\.alphanetworkmc\.com [NC]
RewriteRule ^(.*)$ https://recover.indst.eu/$1 [R,L]

RewriteCond %{HTTP_HOST} ^adminmail\.alphanetworkmc\.com$
RewriteCond %{REQUEST_URI} !^/mail/admin/
RewriteRule ^(.*)$ /mail/admin/$1 [L] 

RewriteCond %{HTTP_HOST} ^adminmail\.alphanetworkmc\.com [NC]
RewriteRule ^(.*)$ https://adminmail.indst.eu/$1 [R,L]

<If "req('Host') == 'recover.alphanetworkmc.com'">
RedirectMatch 301 ^/mail/admin/users/login\.php$ /users/password-recover.php
RedirectMatch 301 ^/mail/admin/login\.php$ /users/password-recover.php
</if>

<If "req('Host') == 'recover.indst.eu'">
RedirectMatch 301 ^/mail/admin/users/login\.php$ /users/password-recover.php
RedirectMatch 301 ^/mail/admin/login\.php$ /users/password-recover.php
</if>

RewriteCond %{HTTP_HOST} mailrules\.alphanetworkmc\.com$
RewriteRule ^(.*)$ https://www.alphanetworkmc.com/threads/e-mail-tos.21/$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^mailrules\.alphanetworkmc\.com [NC]
RewriteRule ^(.*)$ https://mailrules.indst.eu/$1 [R,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^(data/|js/|styles/|install/|favicon\.ico|crossdomain\.xml|robots\.txt) - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
</IfModule>

# php -- BEGIN cPanel-generated handler, do not edit
#Set the “ea-php70” package as the default “PHP” programming language.
<IfModule mime_module>
AddType application/x-httpd-ea-php70___lsphp .php .php7 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit

我的 VPS 上有许多不同的网站,其中包含许多子域重定向。

这是网络错误:

Internal Server Error

The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator at webmaster@localhost to inform them of the time this error occurred, and the actions you performed just before this error.

More information about this error may be available in the server error log.
Apache/2.4.25 (Debian) Server at entertainment.indst.eu Port 80

非常感谢您的帮助。

web-server .htaccess mod-rewrite apache2 500-error
  • 1 1 个回答
  • 9492 Views

1 个回答

  • Voted
  1. Best Answer
    Gerrit
    2020-02-08T01:20:20+08:002020-02-08T01:20:20+08:00

    是的,来自此处子域的每个 URI 都有一个重写循环,它不映射到文件名或目录。

    例如,如果客户端带有mail.indst.eu/nofile

    • 点击子域规则 mail.indst.eu 获取条件!^/mail -> 重写为 mail.indst.eu/mail/nofile
    • 不再匹配 !^/mail,不符合任何外部重定向规则,因此最终失败。
      • 与现有文件的重写排除或硬编码排除之一不匹配
      • 命中非主机绑定的 all-uri 规则,被重写为 mail.indst.eu/index.php
    • 现在它再次匹配子域规则 mail.indst.eu 条件!^/mail -> 重写为 mail.indst.eu/mail/index.php
    • 不再匹配 !^/mail,不符合任何外部重定向规则,因此最终失败。
    • 命中非主机绑定的 all-uri 规则,显然 mail/index.php 不是现有文件,因此 /mail/index.php 被重写为 /index.php,现在我们在 /index 之间交替重复。 php 和 /mail/index.php

    /nofile
    /mail/nofile (does not exist)
    /index.php
    /mail/index.php (does not exist)
    /index.php
    /mail/index.php (does not exist)
    ...repeat last two...
    

    如果您将 index.php 放在子域使用的子目录中,那么子域上不存在的文件 uri 将最终出现在匹配的 subdomain/index.php 文件中,这对于某些应用程序可能是您想要的。如果您想要一个服务器级别的 404 响应,那么您必须从对 index.php 的全部重写中排除子域主机。

    例如

    RewriteCond %{HTTP_HOST} !^mail\.indst\.eu$
    RewriteCond %{HTTP_HOST} !^www\.statesanalytics\.com$
    RewriteRule ^.*$ index.php [NC,L]
    

    或者,这可能更简洁,并允许更多子域:

    RewriteCond %{REQUEST_URI} !^/mail
    RewriteCond %{REQUEST_URI} !^/sa
    RewriteRule ^.*$ index.php [NC,L]
    

    然后,如果 mail/starting-path 中不存在 mail.indst.eu/starting-path 中不存在的 uri,则服务器级别不存在

    还有其他技术可以防止此类循环。例如,如果您知道最多总会有一个内部重定向,并且所有重写器都驻留在这个 .htaccess 中,那么您可以将其作为.htaccess 中的第一个重写器来执行:

    RewriteCond %{ENV:REDIRECT_STATUS} !^$
    RewriteRule ^(.*)$ - [L]
    

    这会阻止来自此 .htaccess 的进一步内部重定向。但这需要您将您拥有的外部重定向规则放在内部重定向规则之前。它不会停止 RedirectMatch 规则。

    或者,如果您知道对 index.php 的全面重写应该始终是使用 [END] 结束 mod_rewrite 处理的最后一个词。但在这种情况下,这意味着子域上的 404 最终会出现在主目录 index.php 中,这可能不是您想要的。

    RewriteRule ^.*$ index.php [END]
    
    • 0

相关问题

  • 提供 70,000 个静态文件 (jpg) 的最佳方式?

  • 持续监控许多服务器运行状况的简单方法?

  • 构建家庭服务器时要考虑的要点[关闭]

  • 用于 Web 应用服务器的 FreeBSD 磁盘分区(Apache/MySQL/PHP)

  • 我需要在 Rackspace 专用/托管网络和数据库 (Linux) 服务器上安装防病毒软件吗?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve