1

我有一个包含两个子域的页面:cw.sidenote.hucellwars.sidenote.hu,它们都指向sidenote.hu/cellwars/

cw.sidenote.hu当我访问或cellwars.sidenote.huURL 更改为/保持格式时,我想实现什么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.

有人可以帮我吗?提前致谢!

4

1 回答 1

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]
于 2012-08-29T09:38:17.373 回答