如何将多个域根目录到多个子文件夹

mat*_*tty 6 .htaccess multiple-domains multiple-sites

我有一个设置,我有几个站点托管在我的FTP根目录中的不同子文件夹中


    ROOT
    -site1folder
    -site2folder

我有2个与该帐户无关的域名.我已将域的DNS记录更改为指向我的主机帐户,但我需要2个不同的URL才能转到正确的子文件夹以加载正确的站点而不是传输域.域名是

  • www.site1.com
  • www.site2.com

理想情况下,我希望site1加载site1文件夹的内容,并为站点2及其相应的文件夹添加相同的内容.

我目前在我的根目录中有一个.htaccess文件,我通过查看不同的帖子将其混合在一起.我是.htaccess的新手.我目前正在尝试将站点1指向site1文件夹


    Options +FollowSymLinks

    #Turns the rewrite engine on.
    RewriteEngine on

    #Fix missing trailing slash character on folders.
    RewriteRule ^([^.?]+[^.?/])$ $1/ [R,L]

    RewriteBase /website1
    #www.site1.co.uk and site1.co.uk will map to the folder

    RewriteCond %{HTTP:Host} ^(?:www\.)?site1\.co.uk
    RewriteRule (.*) /site1 [NC,L,NS]
Run Code Online (Sandbox Code Playgroud)

当我加载它时会发生什么是我获取site1文件夹的内容但在此URL site1.co.uk/site1

我不希望URL完全改变.我只是想加载它所指向的子文件夹的内容.

任何想法都会受到高度赞赏,即使它不能,也不应该以不同的方式做到这一点.

mat*_*tty 18

好的人我终于在经过大量的敲击和阅读大量文档来解密其他代码之后设法自己解决了这个问题.这就是我做的......



    Options +FollowSymLinks


    RewriteEngine on
    #========================================================================
    # FIRST Handle the http requests first before removing the additional url junk
    #========================================================================
    #rule for site1.com to link to site1folder directory
    RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
    RewriteCond %{REQUEST_URI} !^/site1folder/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /site1folder/$1
    #rule for site2.com to link to site2folder directory. Its the same as above just with site2 URL and subfolder
    RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
    RewriteCond %{REQUEST_URI} !^/site2folder/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ /site2folder/$1

    #==========================================================
    # SECOND Remove the additional url junk once the new url is loaded
    #==========================================================
    #rule for site1 url rewrite to remove /site1foler/index.php from the URL
    RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
    RewriteRule ^(/)?$ site1folder/index.php
    #rule for site2 url rewrite to remove /site2foler/index.php from the URL. Again its the same as above just with the site2 URL and sub folder info.
    RewriteCond %{HTTP_HOST} ^(www.)?site2.com$
    RewriteRule ^(/)?$ site2folder/index.php
Run Code Online (Sandbox Code Playgroud)

希望你能看到重复的位置,所以如果你希望在线上添加更多的网站,你可以通过复制和粘贴数据并更改网站URL和子文件夹来匹配你想要添加的其他网站.

我希望这能成功帮助你们中的一些人.此外,如果你能看到这方面的问题,那么我将非常感激,因为我是.htaccess文件的新手,你可以想象,我认为它的工作原理,它必须是正确的.