【发布时间】:2021-06-19 03:33:13
【问题描述】:
我已经为 ubuntu 上的虚拟主机配置了带有 lucee tomcat 和 apache2 的服务器。我启用了重写规则,我的虚拟主机如下。
<VirtualHost *:80>
ServerAdmin admin@example.com
ServerName example.com
ServerAlias example.com www.example.com
DocumentRoot /var/www/html/example.com/
<Directory /var/www/html/example.com/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error_main_example.log
CustomLog ${APACHE_LOG_DIR}/access_main_example.log combined
DirectoryIndex index.cfm
</VirtualHost>
从 htaccess 文件重定向工作正常,但重写规则不起作用。这是我正在尝试的 htaccess 文件。
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^(.*)/abc/([0-9]+)$ /test-404.cfm [L]
以下是示例 URL:
https://www.example.com/example.cfm/abc/2
https://www.example.com/example.cfm/abc/8
https://www.example.com/example.cfm/abc/15
它向我显示 Tomcat 404 错误
HTTP Status 404 – Not Found
Type Status Report
Message The requested resource [/example.cfm/abc/2] is not available
Description The origin server did not find a current representation for the target resource or is not willing to disclose that one exists.
Apache Tomcat/9.0.35
任何机构都可以帮助我解决这个问题。顺便说一句,站点是使用 AWS 上的经典负载均衡器配置的。
【问题讨论】:
-
所以
/test-404.cfm应该在这里显示 不同的 404 错误消息,或者究竟是什么问题? -
@CBroe 是的。实际上 test-404 显示了这些类型的 URL 的一些内容。问题是它没有重写而是显示tomcat 404错误。
-
该模式应与您提到的 URL 匹配。如果您删除之前进行的其他重写内容,并在 RewriteEngine On 后仅保留这条规则,会发生什么?
-
仅供参考,启用重写日志记录通常也有助于弄清楚到底发生了什么。
-
@CBroe。才发现。当 url 模式如下或 cfm 文件:/example.cfm/abc/15 时,重写规则不适用。但如果我使用 /example.php/abc/15 网址。它正在正确重写。因此 apache2 不考虑将 cfm 作为此类 URL 的文件。我可以在哪里定义一些吗?
标签: .htaccess apache2 tomcat9 lucee