0

我有 2 个域指向我网站的根目录:

http://site1.com
http://site2.com

both point to http://dXXXXXXX.domain.com/

我将每个站点都设置为在子目录(同名)中查找其文件,所以

http://site1.com files are located in http://dXXXXXXX.domain.com/site1/
http://site2.com files are located in http://dXXXXXXX.domain.com/site2/

我想为 site1(可能还有 site2)创建一个特殊的子域,它实际上指向主目录中的一个文件夹(两个域可以共享的论坛)。我想用子域网址屏蔽真实网址,如下所示:

http://subdomain.site1.com masks http://dXXXXXXX.domain.com/shared_folder/ (not redirected)

我的 .htaccess 文件(在最顶层目录中)如下所示:

Options +FollowSymLinks
RewriteEngine On

# Rewrite "www.domain.com -> domain.com" 
<IfModule mod_rewrite.c>
  RewriteCond %{HTTPS} !=on
  RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
</IfModule>

# redirect site1.com to /site1 [folder]
# redirect site2.com to /site2 [folder]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^([^0-9]+)$ [NC]
RewriteRule ^(.*)$ /%1/$1 [QSA,L]

#i think this should work but it doesn't
#RewriteCond %{HTTP_HOST} ^subdomain\.site1\.com$ [NC]
#RewriteRule ^$ shared_folder [P]

另外,如果可能的话,我想将每个域的绝对路径重定向到我的首选路径,如下所示:

http://dXXXXXXX.domain.com/site1/ redirects to http://site1.com
http://dXXXXXXX.domain.com/site2/ redirects to http://site2.com

不确定是否有人会找到这些链接,但我希望通过对同一内容没有多个访问点来保持一切清洁(故意共享的 css 或论坛软件除外)

提前感谢您对我的任何帮助或见解

4

1 回答 1

0

我想我想通了(因为它还没有坏掉!)

Options +FollowSymLinks
RewriteEngine On

# Rewrite/Redirect "www.domain.com -> domain.com" 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Rewrite/Redirect "domain.com/foo -> domain.com/foo/"
RewriteCond %{REQUEST_FILENAME} !-f         
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$   
RewriteRule ^(.*)$ /$1/ [R=301,L]       

# Redirect/Pass through "subdomain.site1.com to /shared_folder/"
RewriteCond %{HTTP_HOST} ^subdomain\.([\w.]+)$ [NC]
RewriteRule ^(.*)$ /shared_folder/ [L]

# Redirect/Pass through site1.com to /site1 [folder]
# Redirect/Pass through site2.com to /site2 [folder]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^([^0-9]+)$ [NC]
RewriteRule ^(.*)$ /%1/$1 [QSA,L]

所以这行得通,但我不确定我的规则的位置:是否最好在域本身之前处理特殊的子域情况,就像我现在的顺序一样;或者如果RewriteRule ^(.*)$ /shared_folder/ [L]最好写成RewriteRule ^$ /shared_folder/ [L]...

如果您对好的或更好的做法有任何见解,我将不胜感激,谢谢。

于 2012-06-09T05:10:47.953 回答