2012-08-29 75 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