A-A+

rewrite apache

2008年11月25日 学习随笔 暂无评论 阅读 1 次

在一个IP下只能做一个站,独立IP用完之后,新建站的话用的都是共享IP,可是国外的IP经常面临被封的命运,所以很多人都想在一个IP下面建多个站。
用IX差不多快1年了,以前没有注意过,经过前一段时间的测试,发现完全可以实现。
RewriteEngine on

# If no-www domain requested, externally redirect to www domain
rewritecond %{http_host} ^mysite.net
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]
#
# If www+subdomain domain requested, externally redirect to subdomain without "www"
rewritecond %{http_host} ^www.([^.]+).mysite.net
RewriteRule (.*) http://%1.mysite.net/$1 [R=301,L]
#
# If subdomain+www domain requested, externally redirect to subdomain without "www"
rewritecond %{http_host} ^([^.]+).www.mysite.net
RewriteRule (.*) http://%1.mysite.net/$1 [R=301,L]
#
# If www domain requested, rewrite html page requests to profile.php with query string
rewritecond %{REQUEST_URI}!^/profile.php
rewritecond %{http_host} ^www.mysite.net
RewriteRule ^([^.]+).html /profile.php?page=$1 [L]
#
# If subdomain requested, rewrite subdomain and html page requests to profile.php with query string
rewritecond %{REQUEST_URI}!^/profile.php
rewritecond %{http_host}!^www.mysite.net
rewritecond %{http_host} ^([^.]+).mysite.net
RewriteRule ^([^.]+).html /profile.php?user=%1&page=$1 [L]
#
# If www domain requested, rewrite home page requests to profile.php with query string page = "home"
rewritecond %{REQUEST_URI}!^/profile.php
rewritecond %{http_host} ^www.mysite.net
RewriteRule ^$ /profile.php?page=home [L]
#
# If subdomain requested, rewrite home page requests to profile.php with query string user=subdomain & page="home"
rewritecond %{REQUEST_URI}!^/profile.php
rewritecond %{http_host}!^www.mysite.net
rewritecond %{http_host} ^([^.]+).mysite.net
RewriteRule ^$ /profile.php?user=%1&page=home [L]

# If non-www domain requested, externally redirect to www domain
rewritecond %{http_host} ^mysite.net
RewriteRule (.*) http://www.mysite.net/$1 [R=301,L]
#
# If www+subdomain or subdomain+www domain requested, externally redirect to subdomain without "www"
rewritecond %{http_host} ^www.([^.]+).mysite.net [OR]
rewritecond %{http_host} ^([^.]+).www.mysite.net
RewriteRule (.*) http://%1.mysite.net/$1 [R=301,L]
#
# if home page requested, rewrite to 'home.html' and pass through to following rules
RewriteRule ^$ /home.html
#
# If www domain requested, rewrite html page requests to profile.php with query string
rewritecond %{http_host} ^www.mysite.net
RewriteRule ^([^.]+).html$ /profile.php?page=$1 [L]
#
# If subdomain requested, rewrite subdomain and html page requests to profile.php with query string
rewritecond %{http_host} !^www.mysite.net
rewritecond %{http_host} ^([^.]+).mysite.net
RewriteRule ^([^.]+).html$ /profile.php?user=%1&page=$1 [L]

 

 

在一个IP下只能做一个站,独立IP用完之后,新建站的话用的都是共享IP,可是国外的IP经常面临被封的命运,所以很多人都想在一个IP下面建多个站。
用IX差不多快1年了,以前没有注意过,经过前一段时间的测试,发现完全可以实现。
因为IX的空间支持.htaccess文件,况且网站都是独立IP,所以我们将网站的域名解析到自己的独立IP,然后在独立IP所在网站的根目录建立一个子文件夹.
例:我现在要在76.163.217.47这个IP下面再做一个站,原有的站是www.92proxy.cn
现在我想再建一个www.86meishi.com的网站。
于是我先在www.92proxy.cn的根目录建立一个meishi的文件夹,然后制作了一个.htaccess文件。

复制内容到剪贴板
代码:

DirectoryIndex default.php index.htm index.php index.html default.htm default.html index.shtml default.shtml
RewriteEngine On
Options All -Indexes
php_value upload_max_filesize 20M
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?lenfans.cn$
RewriteCond %{REQUEST_URI} !^/lenfans/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /lenfans/$1
RewriteCond %{HTTP_HOST} ^(www.)?lenfans.cn$
RewriteRule ^(/)?$ lenfans/index.php [L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?86meishi.com$
RewriteCond %{REQUEST_URI} !^/meishi/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /meishi/$1
RewriteCond %{HTTP_HOST} ^(www.)?86meishi.com$
RewriteRule ^(/)?$ meishi/index.php [L]
ErrorDocument 401 /404.htm
ErrorDocument 403 /404.htm
ErrorDocument 404 /404.htm
ErrorDocument 500 /404.htm

DirectoryIndex default.php index.htm index.php index.html default.htm default.html index.shtml default.shtml
这个是定义默认首页的
RewriteEngine On
Options All -Indexes
php_value upload_max_filesize 20M
这个是修改程序上传文件大小的
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?lenfans.cn$
RewriteCond %{REQUEST_URI} !^/lenfans/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /lenfans/$1
RewriteCond %{HTTP_HOST} ^(www.)?lenfans.cn$
RewriteRule ^(/)?$ lenfans/index.php [L]
这个是我绑定的另外一个域名。(网站还没建好,呵呵)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?86meishi.com$ 这个是域名
RewriteCond %{REQUEST_URI} !^/meishi/   这个是目录设置
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /meishi/$1 目录设置
RewriteCond %{HTTP_HOST} ^(www.)?86meishi.com$   域名
RewriteRule ^(/)?$ meishi/index.php [L] 默认访问的文件,可以修改成别的
上面这个就是我绑定的www.86meishi.com的域名了,呵呵。
ErrorDocument 401 /404.htm
ErrorDocument 403 /404.htm
ErrorDocument 404 /404.htm
ErrorDocument 500 /404.htm
这些是错误文档定义。

其实.htaccess文件很强大的,可以实现很多功能,甚至可以定义php参数,比如上传文件大小,PHP程序运行时间等等,只要善于发掘,就能够实现更多的功能。

标签:

给我留言

Copyright © 浩然东方 保留所有权利.   Theme  Ality 07032740

用户登录