Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache .htaccess让子域充当主域_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Apache .htaccess让子域充当主域

Apache .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} !(

我想创建子域只是一个网页的主域。我不想复制文件,所以我尝试使用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} !(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
可以使用