简体   繁体   中英

.htaccess let subdomain behave as main domain

I would like to create subdomain just for one page of main domain. I don't want to have copy of files so i try to solve it using mod_rewrite.

Simply when i go to submdomain.domain.com i want to show page xyz.html as index.html with all pictures. The mod rewrite should keep address in browser url as 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] 

this .htaccess is saved in subdomain of root directory. Unfortunately it works only separatly. First half works only when second half is missing and vice versa. So i am able to do redirect to show only xyz.html page as index page but without images, or do redirect for all subdomain files but xyz.html is ignored and main domain index.html is used.

at the end i have found the solution

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

it is possible to test rules using htaccess tester

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM