Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
Apache 将子域映射应用到Hostgator中的加载项域_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache 将子域映射应用到Hostgator中的加载项域

Apache 将子域映射应用到Hostgator中的加载项域,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我有两个域名,都托管在hostgator上(无限域名婴儿计划) 1.foo.com(这是第一个在HG上注册的域名) 2.bar.com(我在HG中将其添加为一个附加域) 目录结构有/public\u html/,它保存了foo.com的所有文件和子目录 /public\u html/有一个名为bar(即public\u html/bar/)的子目录,用于保存bar.com的所有文件。这是HG在插件域过程中设置的。因此,bar.com的文件将显示如下:/public\u html/bar/proc

我有两个域名,都托管在hostgator上(无限域名婴儿计划)
1.foo.com(这是第一个在HG上注册的域名)
2.bar.com(我在HG中将其添加为一个附加域)

目录结构有
/public\u html/
,它保存了foo.com的所有文件和子目录

/public\u html/
有一个名为
bar
(即
public\u html/bar/
)的子目录,用于保存bar.com的所有文件。这是HG在插件域过程中设置的。因此,bar.com的文件将显示如下:
/public\u html/bar/process.php

我想要这个:
sss.bar.com/fff
->
bar.com/process.php?sub=sss&file=fff

但我发现查找失败了

这就是我尝试的:(这个文件是
/public\u html/bar/.htaccess
-foo.com的父目录中有一个单独的.htaccess,它有一个不相关的规则)

测试:
1.
bar.com/myFile
->在process.php中生成[file]=>myFile-good的GET parm。
2.
test.bar.com/myFile
不起作用

错误是:

找不到test.bar.com上的服务器,因为 DNS查找失败

  • bar.foo.com/file1
    导致获取[file]=>/process.php[sub]=>bar
  • 我认为这可能是由于HG将我的附加域构造为子域的方式。所以现在它认为我正在尝试重新映射一个子域中的一个子域…如果这有意义的话

    谢谢

    更新
    在添加通配符子域并按如下所示修改.htaccess之后,它看起来好像正在按需要工作

    Options +FollowSymlinks  
    RewriteEngine On  
    
    RewriteCond %{REQUEST_FILENAME} !-f  
    RewriteCond %{REQUEST_FILENAME} !-d  
    
    RewriteCond %{HTTP_HOST} !^www  
    RewriteCond %{HTTP_HOST} !^bar\.com$  
    
    RewriteCond %{HTTP_HOST} ^(^.*)\.bar\.com$  
    
    RewriteRule ^(.*)/$  index.php?userId=%1&fileName=$1  
    

    您的
    test.bar.com
    子域很可能是全球DNS系统所未知的。要让它知道,您必须向DNS系统注册它。(如果这只是供您私人使用而非公开使用,您可以使用系统
    /etc/hosts
    文件将名称映射到服务器ip)

    我假设Hostgator是
    foo.com
    (主域名)和
    bar.com
    (附加域名)的
    域名注册商,您有权访问域控制面板(CPanel/Plesk/等)以执行所需操作

    当你为你的主域名(
    foo.com
    )购买一个附加域名(
    bar.com
    )时,Hostgator会为
    bar.com
    设置一个指向同一
    主机的DNS
    CNAME
    (规范名称记录)记录(也称为记录/地址记录)您的主域,以便两个域共享相同的主机。因此,您现在必须对
    测试
    bar.com
    子域执行相同的操作。您可以在Hostgator中找到简短的指南:。
    注意:对DNS记录的更改可能需要几个小时才能生效

    每当你想要一个新的子域时,手动设置它们会让你很恼火。许多域名注册商(包括)也支持一种称为通配符域的功能。它们允许您对指向主域的
    CNAME
    记录使用
    *
    (通配符)。这使得
    where.bar.com
    指向
    www.bar.com
    指向的地址相同

    为了支持主域、附加域及其子域的各个站点,Apache使用基于域名的虚拟主机。如果要为
    whatever.bar.com
    加载与
    www.bar.com
    相同的站点,Apache允许在指令中使用
    *
    通配符。确保在
    www.bar.com
    虚拟主机配置中设置了服务器别名。否则,您必须为每个子域设置单独的VirtualHost配置。
    注意:还有一个apache指令,可用于根据域名提供单独的文档根。

    工作示例 输入:
    结果:index.php获取参数:

    Array
    (
        [userId] => mary
        [fileName] => awesome
    )  
    
    这是最后一个.htaccess,一旦设置了通配符子域,我就开始工作了。添加说明(主要是为了帮助我)


    如果
    test.bar.com
    尚未注册,那么它将无法在DNS服务器上找到,.htaccess无法更改该行为。我的目的是让我网站的用户能够共享自定义链接(例如
    mary.bar.com/awesome
    将转换为调用
    process.php
    ,使用
    userId=“mary”的GET parms
    filename=“awesome”
    由于我不知道谁会提前使用,我正在寻找一条通配符路线。我将在稍后测试一些建议时进行更新。感谢您的贡献。用反斜杠跳过
    bar.com
    中的
    。感谢您的详细回复,并感谢您的额外教育。我添加了一个wil今早HG中的dcard子域。很明显,它需要几个小时才能被看到,所以我们还无法测试它。我实际上想要有许多子域(对于我站点的每个用户),因此,使用通配符似乎是一个不错的选择。明天我将发布测试结果。干杯!DNS记录更改不是即时的;我在回答中添加了一个注释。使用
    CNAME
    通配符记录集,您的所有子域都可用(甚至在您考虑其名称之前)。每个sudomain的功能取决于您如何配置Apache web服务器。它正常工作了!我已更新了问题以反映我所做的更改。实现中是否存在任何潜在问题?
    Array
    (
        [userId] => mary
        [fileName] => awesome
    )  
    
    Options +FollowSymlinks
    RewriteEngine On
    
    # 1. Parse the subdomain as a variable we can access in PHP
    # 2. Parse out the filename (must have a trailing "/" on the end)
    # 3. Pass the vars into index.php script
    # Make sure a wildcard subdomain is setup (takes 24-48hrs to propagate) and points to the addon domain folder
    # ex: "public_html/addon-domain-name.tld"
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # make sure we don't process "www.domain.com" or "domain.com".  This will just default to index.php with no GET vars
    RewriteCond %{HTTP_HOST}        !^www
    RewriteCond %{HTTP_HOST} !^bar\.com$
    
    # This part pulls out the subdomain from the front of the URL & stores it in "%1"
    # Note: it is possible that the subdomain can have multiple parts (ex bob.smith.domain.com) and still work
    #       The user id is either numeric or string [Aa-Zz], so add error checks inside index.php
    RewriteCond %{HTTP_HOST} ^(^.*)\.bar\.com$
    
    # IMPT: do not rewrite the rule until the trailing filename is parsed out
    #       otherwise .htaccess will try to parse out something from index.php
    # Parse out the filename that comes after domain.com (stored in "$1").  A trailing "/" is required.
    RewriteRule ^(.*)/$  index.php?userId=%1&fileName=$1