Apache .htaccess让子域充当主域
我想创建子域只是一个网页的主域。我不想复制文件,所以我尝试使用mod_rewrite解决它 当我转到submdomain.domain.com时,我只想将xyz.html页面显示为index.html,并显示所有图片。mod rewrite应将浏览器url中的地址保留为subdomain.domain.comApache .htaccess让子域充当主域,apache,.htaccess,mod-rewrite,Apache,.htaccess,Mod Rewrite,我想创建子域只是一个网页的主域。我不想复制文件,所以我尝试使用mod_rewrite解决它 当我转到submdomain.domain.com时,我只想将xyz.html页面显示为index.html,并显示所有图片。mod rewrite应将浏览器url中的地址保留为subdomain.domain.com RewriteEngine On RewriteCond %{HTTP_HOST} ^subdomain.domain.com RewriteCond %{REQUEST_URI} !(
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteCond %{REQUEST_URI} !(index.html)
RewriteRule ^(.*) http://www.domain.com/$1 [P,L]
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteCond %{REQUEST_URI} index.html
RewriteRule index.html http://www.domain.com/xyz.html [P,L]
此.htaccess保存在根目录的子域中。不幸的是,它只能单独工作。前半部只有在后半部缺失时才起作用,反之亦然。因此,我可以重定向以仅显示xyz.html页面作为索引页面,但不显示图像,或者重定向所有子域文件,但忽略xyz.html并使用main domain index.html 最后我找到了解决办法
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteCond %{REQUEST_URI} index.html
RewriteRule index.html http://www.domain.com/myspecial-page.html [P,L]
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteRule ^([a-zA-Z0-9\.\-\_]+).html$ http://www.domain.com/$1.html [NC]
RewriteCond %{HTTP_HOST} ^subdomain.domain.com
RewriteRule ^images/([a-zA-Z0-9\.\-\_]+)$ http://www.domain.com/images/$1 [NC,P]
etc...for css, js
可以使用