我试图保持我的主域结构不会太杂乱,所以我将我的所有域解析为他们自己的子文件夹。所以,我想要做的是当用户前往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]
然而,它会破坏我加载到主目录中的所有其他子域。
有关如何解决此问题的任何想法?
答案 0 :(得分: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]
答案 1 :(得分: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>