Redirect subdomain to primary domain except for one URL

Hi, I have a main domain as follows

Primary domain: http://www.sample.com/

Sub domain: http://dev.sample.com/

Now, if any access to http://dev.sample.com/ is needed, it needs to be redirected to http://www.sample.com/ so I added the following code to my subdomain. It works very well.

RewriteCond %{HTTP_HOST} !www.sample.com.com$ [NC]

RewriteRule ^(.*)$ http://www.sample.com.com/$1 [L,R=301]

But from the subdomain, if there is any access to the following URL http://dev.sample.com/data , then it should not be redirected to the main domain. It should remain on this subdomain page. Anyone have an idea?

+5
source share
2 answers

:

RewriteCond %{HTTP_HOST} ^dev\.sample\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?data
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,QSA,R=301]
+2

:

RewriteCond %{HTTP_HOST} !www\.sample\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/data [NC]
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,R=301]

URL / URI. , http://blog.sample.com/data, . , ... , :

RewriteCond %{HTTP_HOST} !dev\.sample\.com$ [NC]
RewriteCond %{HTTP_HOST} !www\.sample\.com$ [NC]
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,R=301]

, , , , dev www /data.

+1

All Articles