首页 > 解决方案 > 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>

谁能帮我解决这个问题?

标签: apachemod-rewrite

解决方案


仅使用您显示的示例,您能否尝试以下操作。确保将这些规则保留在 .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 之前清除您的浏览器缓存。


推荐阅读