mod-rewrite - / 的 Apache 2.2 重写规则未重定向
问题描述
我在 apache 中有配置文件,应该将/请求重定向到不同的 url。
但是当我点击/时我得到 404
请求将发送到后端服务器,但它没有重定向。
配置文件是
#This is not getting invoked. Returning 404.
#Request is redirected to app2.adobecqms.net with out appending page1/page2.html
RedirectMatch ^/$ https://app1.abc.com/page1/page2.html
RewriteCond %{REQUEST_URI} ^/folder1/folder2
RewriteCond %{REQUEST_URI} !^/(.*)\.(json|html)
RewriteRule ^/(.*)$ http://app2.adobecqms.net/$1.html [P]
RewriteCond %{REQUEST_URI} ^/analytics.txt
RewriteRule ^/(.*)$ http://app2.adobecqms.net/page1/page2/page3/$1 [P]
#I also tried with below. But no luck
#This is returning 502
#RewriteRule ^/$ https://app1.abc.com/page1/page2.html [P]
任何想法?
解决方案
#This is not getting invoked. Returning 404. #Request is redirected to app2.adobecqms.net with out appending page1/page2.html RedirectMatch ^/$ https://app1.abc.com/page1/page2.html
因为您使用的是 mod_aliasRedirectMatch
指令,它在其他 mod_rewrite ( ) 指令之后RewriteRule
进行处理,尽管配置文件中的指令顺序不同。
和/或您有ProxyPass
转发其他请求的指令?需要 mod_rewrite 来覆盖它。
您还需要在RewriteRule
此处使用 mod_rewrite 以避免冲突。例如:
RewriteRule ^/$ https://app1.abc.com/page1/page2.html [R=302,L]
而且这个指令应该在现有指令之前。(尽管在这种情况下不应该有冲突。)L
标志是必需的。
该P
标志通过 mod_proxy 发送请求 - 这不是“重定向”。
您发布的RedirectMatch
指令将默认为 302(临时)重定向,正如我在此处使用的那样。但是,如果这是永久性的,则更改为 301,但前提是您确认它按预期工作(以避免缓存问题)。
推荐阅读
- sql-server - SQL Server 2016 - 开发者版开发 - 标准版生产
- windows - Julia stdin 错误与 WIndows 中的 Vim 和 AsyncRun
- php - 带有子查询的 Doctrine QueryBuilder
- jenkins - Jenkinsfile 管道访问“全局密码”
- regex - 用于目标的 Google Analytics Reg Ex
- linux-kernel - cgroups blkio 子系统未正确计算容器应用程序的块写入字节数
- javascript - 避免回调地狱和组织 Node.js 代码
- batch-file - 使用批处理脚本打开文件
- android - android studio 在 Viewflipper 中给出 OutOfMemoryError
- java - JPA 工具正在生成具有数据库中“旧”/已删除列的实体