【问题标题】:setting up a subdomain to point to a folder using htaccess使用 htaccess 设置子域以指向文件夹
【发布时间】:2010-06-27 07:19:10
【问题描述】:

大家好,我已经使用 zend 框架并使用干净的 url 构建了一个网站 - 但是我需要设置一个子域,使其仅指向我网站上的一个文件夹,即我希望子域 admin.mysite.com 指向mysite.com/admin 我想用我的 htaccess 文件来做

编辑-------

这是我的 htaccess 文件:

RewriteEngine on

RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php
RewriteRule !\.(js|ico|gif|jpg|png|css|htm|html)$ index.php 

RewriteCond %{REQUEST_URI} !^/admin
RewriteCond %{HTTP_HOST} ^admin
RewriteCond %{REQUEST_URI} !^/admin
RewriteRule ^(.*)$ admin/$1 [L]


AddType text/css .css
AddHandler php5-script .php

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    在您现有的 URL 重写之上尝试这样的操作:

    RewriteCond %{HTTP_HOST} ^admin
    RewriteCond %{REQUEST_URI} !^/admin
    RewriteRule ^(.*)$ admin/$1 [L]
    

    编辑:为了防止它被解释为 Zend Frameowrk 控制器,请在您现有的 RewriteConds 上方添加以下内容,以防止它转换您的管理 URL:

    RewriteCond %{REQUEST_URI} !^/admin
    

    我认为这应该可以解决所有问题。

    编辑:您的 .htaccess 文件应该类似于以下内容,尽管我不认为任何更改都与您的 403 错误有关,但也许我们会很幸运的。如果没有,我会继续考虑可能导致这种情况的原因。

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^mysite.com [NC]
    RewriteRule (.*) http://www.mysite.com/$1 [L,R=301]
    
    # Don't rewrite requests on admin subdomain to the Zend Framework handler
    RewriteCond %{HTTP_HOST} !^admin
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule .* index.php
    
    RewriteCond %{HTTP_HOST} !^admin
    RewriteRule !\.(js|ico|gif|jpg|png|css|htm|html)$ index.php [L]
    
    RewriteCond %{HTTP_HOST} ^admin
    RewriteCond %{REQUEST_URI} !^/admin
    RewriteRule ^(.*)$ admin/$1 [L]
    
    AddType text/css .css
    AddHandler php5-script .php
    

    【讨论】:

    • 我不希望管理文件夹被视为控制器 - 实际上我的管理面板是一个不同的应用程序,所以我希望它独立运行。我的旧主机有一个非常简单的面板来创建子域,但在我的新主机上,我必须在 htaccess 文件中写入:(
    • 啊,明白了。我现在已经更新了答案,你可以试试看是否有效。
    • 我因为某些奇怪的原因收到 403 错误?我的管理文件夹在我的 public_html 文件夹中...
    • 您的.htaccess 文件在您的public_html 文件夹中,对吧?
    • 是的,完全正确.. 它对其他所有东西都可以正常工作.. 让我显示 htaccess 文件
    【解决方案2】:

    在 admin.mysite.com“/”上,您可以符号链接到“/admin”

    【讨论】:

      【解决方案3】:

      在子域 admin.mysite.com 上使用指令重定向。

      Redirect permanent / http://mysite.com/admin
      

      或者你可以使用代理:

      ProxyPass / http://mysite.com/admin
      ProxyPassReverse / http://mysite.com/admin
      ProxyPreserveHost on
      

      【讨论】:

        猜你喜欢
        • 2010-12-07
        • 2013-11-22
        • 2013-11-26
        • 2023-03-16
        • 1970-01-01
        • 2014-03-17
        • 1970-01-01
        • 2013-09-03
        • 2011-10-14
        相关资源
        最近更新 更多