1

我试图避免我的主要域结构过于混乱,所以我将我的所有域解析到它们自己的子文件夹中。所以,我想做的是当用户访问http://mydomain.com他们实际上被发送到http://mydomain.com/sub-directory

这段代码有效:

#redirect to submain subdomain
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /submain/
RewriteRule ^submain/(.*) /$1 [L,R=301]
RewriteRule !^submain/ submain%{REQUEST_URI} [L]

但是,它破坏了我已加载到主目录中的所有其他子域。

有想法该怎么解决这个吗?

4

2 回答 2

2
RewriteEngine On
RewriteCond %{THE_REQUEST} ^GET\ /submain/
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$
RewriteRule ^submain/(.*) /$1 [L,R=301]

RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$
RewriteRule !^submain/ submain%{REQUEST_URI} [L]
于 2013-06-26T21:37:02.110 回答
0
Create a .htaccess file in root folder, and put this content inside(just change example.com and my_subdir):

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/my_subdir/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /my_subdir/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ my_subdir/index.php [L] 
</IfModule>
于 2017-07-29T11:29:06.380 回答