Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 如何将我的sudomains Web空间重定向到实际的子域?_.htaccess_Redirect_Mod Rewrite - Fatal编程技术网

.htaccess 如何将我的sudomains Web空间重定向到实际的子域?

.htaccess 如何将我的sudomains Web空间重定向到实际的子域?,.htaccess,redirect,mod-rewrite,.htaccess,Redirect,Mod Rewrite,我想重定向到 正如您所知,子域Web空间位于实际的域Web空间中;这会导致内容重复 我已经试过了: 将javascript添加到index.php的头部: document.location.href=https://example.com/sub/index.php'; 但这会创建一个infinte循环 正在将.htaccess添加到/sub/目录: RewriteEngine On RewriteRule (.*) https://sub.example.com/index.php$1 [

我想重定向到

正如您所知,子域Web空间位于实际的域Web空间中;这会导致内容重复

我已经试过了:

  • 将javascript添加到index.php的头部:

    document.location.href=https://example.com/sub/index.php';
    
    但这会创建一个infinte循环

  • 正在将.htaccess添加到/sub/目录:

    RewriteEngine On
    RewriteRule (.*) https://sub.example.com/index.php$1 [R=301,L]
    
    但这使得在/sub/中创建其他文件变得不可能,因为它总是将您重定向到index.php


  • 如果我还想在/sub/中创建其他文件,这些文件总是重定向到子域版本,那么解决这个问题的最佳方法是什么?

    放置在站点根目录下的以下内容应该将点击
    example.com/sub
    的任何内容重定向到
    sub.example.com

    RewriteEngine On 
    RewriteRule ^sub/(.*)$ http://sub.example.com/$1 [R=301,NC,L]
    

    如果需要调整这些规则,您可以在进行测试。

    子目录结构与子域结构相同吗?即将
    http://sub.example.com/path/to/my/file.php
    重定向到
    http://example.com/sub/path/to/my/file.php
    ?@bluemoon6790应该是另一种方式,但是是的