【问题标题】:Using .htaccess to point primary domain to subfolder without altering the URL使用 .htaccess 将主域指向子文件夹而不更改 URL
【发布时间】:2017-04-15 08:45:16
【问题描述】:

我有一个域,即 www.domain.org,并希望将其指向我服务器上的子文件夹。主域从 /public_html 加载,现在我想从 /public_html/domain2017 加载域。

我在网上研究了各种解决方案,但我得到的只是重定向。 重定向不是首选,因为当我想保持 www.domain.org 但加载 www.domain.org/domain2017 的 index.php 文件时,我最终得到了 www.domain.org/domain2017。希望这是有道理的。注意:我在 public_html/domain2017 中安装了 WordPress。

以下是我的 .htaccess 的示例内容

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(www\.)?domain\.org$ [NC]
RewriteRule !^subdir/ /domain2017%{REQUEST_URI} [L,NC]
</IfModule>

Solution Attempt 1Solution Attempt 2Solution Attempt 3Solution Attempt 4

我已经尝试了上述所有链接,它们只是将我的域重定向到 URL,并且不会阻止地址栏中的 URL 更改

【问题讨论】:

    标签: wordpress apache .htaccess shared-hosting


    【解决方案1】:

    你可以使用下面的htaccess:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC,OR]
    RewriteCond %{HTTP_HOST} ^www.yourdomain.com$
    RewriteCond %{REQUEST_URI} !public_html/domain2017/
    RewriteRule (.*) /public_html/domain2017/$1 [L]
    

    【讨论】:

    • 我收到以下错误 Not Found The requested URL /public_html/.....2017/ was not found on this server.此外,在尝试使用 ErrorDocument 处理请求时遇到 404 Not Found 错误。
    猜你喜欢
    • 2015-12-01
    • 2010-12-07
    • 2015-05-09
    • 2016-06-03
    • 2013-11-22
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多