apache - 我正在尝试将 /example 重定向到 Apache 的 httpd.conf 中的 example.html,但它不起作用
问题描述
这是我试图在 httpd.conf 中应用的代码:
<VirtualHost *:80>
ServerName www.test.com
ServerAlias www.test.com
DocumentRoot /home/test_com
ErrorLog /home/logs/apache/www_test/www.test.com-error_log
CustomLog /home/logs/apache/www_test/www.test.com.-access_log common env=!do_not_log
# https redirect
RewriteEngine On
RewriteCond %{HTTP_HOST} www.test.com
RewriteCond %{REQUEST_URI} /example
RewriteRule . https://www.test.com/example.html [R=303,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}
<Directory "/home/test_com/">
Options Indexes FollowSymLinks
AllowOverride None
Require all granted
</Directory>
</VirtualHost>
应用代码并重新启动 apache 后,当我转到 /example 时,我得到一个 404 not found 响应。
当我在 ( https://htaccess.madewithlove.be )测试 htaccess 时,输出是我想要的https://www.test.com/example.html 。我想知道问题是什么。
解决方案
RewriteRule 的右侧部分是目标文件,尝试更改:
RewriteCond %{REQUEST_URI} /example
至 :
RewriteCond %{REQUEST_URI} /example.html
推荐阅读
- ruby-on-rails - 如何在 Github 上更新已删除的文件
- node.js - 错误:请求类型无效或未知(不是 Dialogflow v1 或 v2 webhook 请求)
- php - 带有端口的 IP URL 在 cURL PHP 中不起作用
- performance - 为什么我的 yarn install / yarn add 速度极慢?
- c# - 如何通过 <> 运算符进行 DataView 行过滤器
- javascript - HTML、JS:使用非常大的数据属性来存储内容?
- flutter - Flutter:如何使用 setAll(0,list) 将列表插入另一个列表
- sql - 递归 CTE 在 SQL Server 中查找层次结构中的第一个管理器
- python - 如何在一行 Python 中放置多行“if elif”
- javascript - JS Popup 的 CSS 动画淡出/淡入