将目录重写为子域

时间:2012-08-29 09:26:34

标签: .htaccess rewrite subdomain

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

当我访问cw.sidenote.hucellwars.sidenote.hu时,我想要实现的目标是,网址更改为/ cellwars.sidenote.hu格式,并且不会更改为{{1} }。

这是我目前在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]

这是我从Chrome回来的:

# 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]

有人能帮帮我吗?提前谢谢!

1 个答案:

答案 0 :(得分: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]