apache - mod_rewrite 子域(带路径)到 URL
问题描述
正在为此苦苦挣扎,并且已经完成了大约 30 分钟以上的谷歌搜索。
我想重定向:
sub.domain.com/path1 to https://anotherdomain.com/path3
sub.domain.com/path2 to https://anotherdomain.com/path4
下面的代码不起作用,但到目前为止演示了我的方法/思考
#CLIENT 1
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mockups.domain.com$
RewriteCond %{REQUEST_URI} ^/client1/
RewriteRule (.*) https://xd.adobe.com/view/xxxxxxxxxxxx/ [L,R]
</IfModule>
# CLIENT 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mockups.domain.com$
RewriteCond %{REQUEST_URI} ^/client2/
RewriteRule (.*) https://xd.adobe.com/view/xxxxxxxxxxxx/ [L,R]
</IfModule>
谁能帮我解决这个问题?
解决方案
仅使用您显示的示例,您能否尝试以下操作。确保将这些规则保留在 .htaccess 文件的顶部,并将其他规则保留在这些规则之下。
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mockups\.domain\.com$ [NC]
RewriteRule ^client1 https://xd.adobe.com/view/your_new_path_here [L,R=302,NE]
RewriteCond %{HTTP_HOST} ^mockups\.domain\.com$ [NC]
RewriteRule ^client2 https://xd.adobe.com/view/your_2nd_path_here [L,R=302,NE]
</IfModule>
另外,请在测试您的 URL 之前清除您的浏览器缓存。
推荐阅读
- python-3.x - Python递归函数计数用户
- angular - 如果在搜索栏中未找到结果,则显示错误消息
- javascript - 无法从 SVG 图像元素加载图像
- java - 如何在 spring-boot 中管理 gRPC 服务器通道
- python - 在鱼眼相机中使用 python 进行人脸识别
- java - java.lang.IllegalStateException:不是标准目录之一:Android 10 上的 /storage/emulated/0/Download/
- docker - 我们可以使用带有基本映像的 RUN 指令作为暂存器吗?
- flutter - Flutter 等待 Provider 准备好在 multiprovider 中
- javascript - 在 Vuetify 自动完成搜索中通过 API 进行搜索非常慢
- intellij-idea - IntelliJ 的断点在“没有在行中找到可执行代码”的情况下快速进出