2012-08-29 79 views
1

我有一个包含两个子域的页面:cw.sidenote.hucellwars.sidenote.hu,均指向sidenote.hu/cellwars/将目录重写为子域

我想达成什么,当我访问cw.sidenote.hucellwars.sidenote.hu的URL变化/留在cellwars.sidenote.hu格式,并且不改变sidenote.hu/cellwars/

这是我目前在我的.htaccess文件:

RewriteEngine on 

# Some hosts require a rewritebase rule, if so, uncomment the RewriteBase line below. If you are running from a subdirectory, your rewritebase should match the name of the path to where stacey is stored. 
# ie. if in a folder named 'stacey', RewriteBase /stacey 
#RewriteBase /cellwars 

ErrorDocument 404 /404.html 

# Rewrite any calls to *.html, *.json, *.xml, *.atom, *.rss, *.rdf or *.txt if a folder matching * exists 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !public/ 
RewriteCond %{DOCUMENT_ROOT}/public/$1.$2 !-f 
RewriteRule (.+)\.(html|json|xml|atom|rss|rdf|txt)$ $1/ [L] 

# Add a trailing slash to directories 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.) 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ([^/]+)$ $1/ [L] 

# Rewrite any calls to /* or /app to the index.php file 
RewriteCond %{REQUEST_URI} /app/$ 
RewriteRule ^app/ index.php [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ index.php?$1 [L] 

# Rewrite any file calls to the public directory 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !public/ 
RewriteRule ^(.+)$ public/$1 [L] 

这些重写规则我心中已经尝试使用,但似乎这得到该网站进入无限循环改写:

# cw.sidenote.hu -> cellwars.sidenote.hu 
RewriteCond %{HTTP_HOST} ^cw.sidenote.hu$ 
RewriteRule ^(.*)$ http://cellwars.sidenote.hu/ [R=301,L] 

# sidenote.hu/cellwars/* -> cellwars.sidenote.hu/* 
RewriteCond %{REQUEST_URI} ^/cellwars/?(.*)$ 
RewriteRule ^(.*)$ http://cellwars.sidenote.hu/%1 [R=301,L] 

这是我从Chrome中回来:

This webpage has a redirect loop 
The webpage at http://cellwars.sidenote.hu/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer. 
Here are some suggestions: 
    Reload this webpage later. 
    Learn more about this problem. 
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects. 

莫非一你帮助我吗?提前致谢!

回答

1

尝试用这个替换您的htaccess文件的内容(我没有改变任何东西超出ErrorDocument 404 /404.html线):

RewriteEngine on 

# Some hosts require a rewritebase rule, if so, uncomment the RewriteBase line below. If you are running from a subdirectory, your rewritebase should match the name of the path to where stacey is stored. 
# ie. if in a folder named 'stacey', RewriteBase /stacey 
RewriteBase/

# cw.sidenote.hu -> cellwars.sidenote.hu 
RewriteCond %{HTTP_HOST} ^cw\.sidenote\.hu$ 
RewriteRule ^(.*)$ http://cellwars.sidenote.hu/$1 [R=301,L] 

# sidenote.hu/cellwars/* -> cellwars.sidenote.hu/* 
RewriteCond %{HTTP_HOST} ^(www\.)?sidenote\.hu$ 
RewriteRule ^cellwars/?(.*)$ http://cellwars.sidenote.hu/$1 [R=301,L] 

ErrorDocument 404 /404.html 

# Rewrite any calls to *.html, *.json, *.xml, *.atom, *.rss, *.rdf or *.txt if a folder matching * exists 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !public/ 
RewriteCond %{DOCUMENT_ROOT}/public/$1.$2 !-f 
RewriteRule (.+)\.(html|json|xml|atom|rss|rdf|txt)$ $1/ [L] 

# Add a trailing slash to directories 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.) 
RewriteCond %{REQUEST_URI} !(.*)/$ 
RewriteRule ([^/]+)$ $1/ [L] 

# Rewrite any calls to /* or /app to the index.php file 
RewriteCond %{REQUEST_URI} /app/$ 
RewriteRule ^app/ index.php [L] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)/$ index.php?$1 [L] 

# Rewrite any file calls to the public directory 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !public/ 
RewriteRule ^(.+)$ public/$1 [L] 
+0

谢谢,但没有奏效。如果我输入了子域名:'cw.sidenote.hu'或'cellwars.sidenote.hu',它会变成'sidenote.hu/cellwars /',并且无法访问我网站上的任何网页。 – szantaii