apache - .htaccess 掩码原始网址
问题描述
我有这个网址:
localhost:1001/project/index.html
如果我写这个 URL:
localhost:1001/project/index.html.twig
我希望它被屏蔽为第一个(localhost:1001/project.index.html
),但处理的 URL 必须是第二个(不知道是否可能)。
我已经尝试了所有这些,但我认为我.htaccess
的项目文件夹根目录中的所有内容都是错误的,因为没有按我的意愿工作:
一个)
RedirectMatch 302 /project/index.html.twig /project/index.html
b)
RedirectMatch 301 /project/index.html.twig /project/index.html
C)
RewriteCond %{HTTP_HOST} ^/project/index.html.twig$ [NC]
RewriteRule /project/index.html [R=301,L]
注释
我想获得的过程:
- 我在浏览器中写:
localhost:1001/project/index.html.twig
- 不知何故,我希望我
.htaccess
将浏览器中的 URL 转换为并在浏览器中localhost:1001/project/index.html
查看该 URL - 之后我想在内部处理原始 URL:
localhost:1001/project/index.html.twig
解决方案
如果您想要外部重定向,这可能就是您正在寻找的内容:
RewriteEngine on
RewriteRule ^/?project/index\.html$ /project/index.html.trig [R=301]
RewriteRule ^/?project/index\.html\.twig$ /project/index.html [END]
如果您想要内部重写,请使用该变体:
RewriteEngine on
RewriteRule ^/?project/index\.html\.twig$ /project/index.html [R=301]
RewriteRule ^/?project/index\.html$ /project/index.html.trig [END]
这些规则应该在 http 服务器主机配置或动态配置文件(“.htaccess”样式文件)中同样起作用。如果您可以访问它,您绝对应该更喜欢第一个选项。如果您需要使用动态配置文件,请注意它的解释是否已启用并且它位于主机的DOCUMENT_ROOT
文件夹中。
如果您使用该规则收到服务器内部错误(http 状态 500),则可能是您操作的是旧版本的 apache http 服务器。[END]
在这种情况下,您会在 http 服务器错误日志文件中找到有关未知标志的明确提示。在这种情况下尝试使用较旧的[L]
标志,它可能在这里工作相同,但这取决于您的设置。
推荐阅读
- angular - 角度路由在子域的刷新页面中不起作用
- unix - 获取 Nginx access.log 中每个请求的每个 IP 的请求数
- ios - 如何在扩展中的 didSet 变量中调用扩展中的函数
- docker - Docker 没有运行
- python - 读取然后写入 CSV 文件的行 - Python3
- amazon-web-services - 如何监控 SQS Redrive 事件
- azure - 在为 ARM 模板部署创建的 Azure DevOps Pipeline 中找不到 JSON 文件路径
- sql - SQL With子句,不同表中的列名相同
- python-3.x - ValueError("I/O operation on closed pipe") 将异步与子进程一起使用时
- sharepoint-online - 重置样本 ID 的增量变量