• HOME
  • DOCS
  • WTF
  • TECH
  • LIFE
  • PAGES
    • ARCHIVE
    • TAGS
    • ABOUT
    • FRIENDS
    • RSS
  • TOOLS
    • GEO
    • RANDOM()
    • GOO.GL
    • CSS HEART
Aj's Blog

记录时间溜走的瞬间和折腾过的那些事

.htaccess rewrite root directory to sub directory

2013-01-05  TECH  .htaccess  CPanel  Rewrite  root directory  sub directory  

用CPanel的同学都知道,帐号的根目录下会绑定一个域名,之后新建的网站也都在这个域名的目录下。

即: A.com => /www, AA.com => /www/AA.com …

当你想同时使用 A.com 和 AA.com 或者更多网站时,目录和文件会非常混乱。

因此想采用Rewrite来处理A.com,这样保证所有文件和目录的整洁。

理想结果:

A.com => /www/A.com, AA.com => /www/AA.com, …

/www/下目录和文件效果:

.htaccess
A.com
AA.com
B.com
…
index.html <== "主机默认页面" 实现方法: 修改 /www/.htaccess

RewriteEngine On

#—limit domain—
RewriteCond %{HTTP_HOST} ^www.A.com$ [OR]
RewriteCond %{HTTP_HOST} ^A.com$

#—if exsisted resource—
RewriteCond %{DOCUMENT_ROOT}/A.com/%{REQUEST_URI} -f
RewriteRule ^(.*)$ A.com/$1 [L]

#—if exsisted directory—
RewriteCond %{DOCUMENT_ROOT}/A.com/%{REQUEST_URI} -d
RewriteRule ^(.*)$ A.com/$1 [L]

#—all other resouce redirect to index.php—
#— for wordpress —
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ A.com/index.php [L,QSA]
下一篇:   用HTA+jQuery进行桌面开发的尝试
上一篇:   Nginx一站多域名$_SERVER[‘SERVER_NAME’]获取错误问题
暂无评论

Cancel reply