RewriteRule导致子域加载另一个DocumentRoot?

时间:2012-07-31 05:13:44

标签: apache .htaccess mod-rewrite subdomain document-root

Apache(大部分)noob在这里......对于RewriteRule .htaccess中的sharpedge.我想要做些什么可以肯定的帮助: ...使用我们的Internet_IE子域名导致URL从httpd.conf目录自动加载 - 比站点根目录深一级。

我在[snip] NameVirtualHost 11.22.33.44 <VirtualHost 11.22.33.44> Options All +ExecCGI ServerAdmin hostmaster@ourhost.com DocumentRoot /var/www/html/ourdomain.com ServerName ourdomain.com ServerAlias www.ourdomain.com DirectoryIndex index.htm index.html index.dna #--------------------------------- <IfModule mod_rewrite.c> RewriteEngine on RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] </IfModule> #--------------------------------- </VirtualHost> <VirtualHost 11.22.33.44> Options All +ExecCGI ServerAdmin hostmaster@ourhost.com DocumentRoot /var/www/html/ourdomain.com ServerName sharpedge.ourdomain.com DirectoryIndex index.htm index.html index.dna #--------------------------------- <IfModule mod_rewrite.c> RewriteEngine on RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L] </IfModule> #--------------------------------- </VirtualHost> [snip]

中有这个
Options -Indexes

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond   %{HTTP_HOST} ^sharpedge\.ourdomain\.com$
    # years ago this next line was used here, but in httpd.conf: (I don't know what it was supposed to do)
    # RewriteRule   ^(.+)        %{HTTP_HOST}$1          [C]
    RewriteRule   ^sharpedge\.ourdomain\.com(.*) /var/www/html/ourdomain.com/Internet_IE/$1  [L]
</IfModule>

...在.htaccess中(在网站根目录中,这里:/var/www/html/ourdomain.com /)

/

..但RewriteRule没有任何反应;好像RewriteRule不在那里。

我非常感谢任何建议。

编辑:

  • 我只是将DocumentRoot更改为我实际想要提供的目录,但是我需要能够从包含路径中前缀为{{1}}的目录中的文件中调用(包含)文件,其中这些文件位于站点根目录中。这些文件也可以从站点根目录中的其他文件中进行类似调用。

1 个答案:

答案 0 :(得分:1)

您不希望将主机的任何部分放在RewriteRule中,但是您有HTTP_HOST权限,请尝试:

RewriteCond %{HTTP_HOST} ^sharpedge\.ourdomain\.com$ [NC]
# to prevent looping
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /Internet_IE/$1 [L]

尝试更改!-f!-d支票:

RewriteCond %{HTTP_HOST} ^sharpedge\.ourdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/Internet_IE/
RewriteRule ^(.*)$ /Internet_IE/$1 [L]