【问题标题】:How to redirect a path to subdomain using htaccess如何使用 htaccess 将路径重定向到子域
【发布时间】:2018-07-10 06:13:04
【问题描述】:

我是 htaccess 新手,需要有关重定向到子域路径的帮助。

我的子域是

Subdomain :  https://abc.example.com/

指向路径

Path :  https://example.com/folder1/abc

现在我想如果有人使用路径访问目录,它应该重定向到子域

Request :  https://example.com/folder1/abc/folder2/file
Redirect : https://abc.example.com/folder2/file

我搜索了很多,但无法继续。任何形式的帮助将不胜感激。

完成我的 htaccess 文件

RewriteEngine on

RewriteCond %{HTTP_HOST} !^api\. [NC]
RewriteRule .* https://api.example.com/$0 [L,NE,R=301]

ErrorDocument 403     /error-pages/403.php
ErrorDocument 404     /error-pages/404.php

【问题讨论】:

    标签: php apache .htaccess redirect mod-rewrite


    【解决方案1】:

    folder1/abc/.htaccess 内部,将此规则作为您的第一条规则:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^abc\. [NC]
    RewriteRule .* http://abc.example.com/$0 [L,NE,R=301]
    

    【讨论】:

    • 谢谢,我试试
    • 只有当我访问 example.com/folder1/abc 时它才会重定向,但如果我访问 example.com/folder1/abc/folder2/file 它不起作用
    • 访问文件返回结果而不是首先重定向到子域。是的,这是我的第一条规则。
    • 我进行了更正,但仍将结果返回给我。重定向不起作用。了解更多信息。它是我用基本 php 编写的 api 服务 url,返回我的 json 数据。所以,我正在接收数据,但重定向不起作用
    • 嘿,现在它可以工作了,我在只有 ErrorDocument 的子文件夹中多了一个 htaccess。我已经删除了这些并且它有效。
    猜你喜欢
    • 2021-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-19
    • 2023-03-09
    • 1970-01-01
    • 2023-03-08
    • 2020-07-10
    相关资源
    最近更新 更多