Hi I have a main domain as follows
Main domain : http://www.sample.com/
Sub domain : http://dev.sample.com/
Now If any one access http://dev.sample.com/ It needs to redirect to http://www.sample.com/ So I added the following code in my sub domain It works very well
RewriteCond %{HTTP_HOST} !www.sample.com.com$ [NC]
RewriteRule ^(.*)$ http://www.sample.com.com/$1 [L,R=301]
But from subdomain if any access the following url http://dev.sample.com/data then it should not redirect to main domain. It should stay on that sub domain page. Any one have idea?
Try these rules :
RewriteCond %{HTTP_HOST} ^dev\.sample\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/?data
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,QSA,R=301]
Try this:
RewriteCond %{HTTP_HOST} !www\.sample\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/data [NC]
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,R=301]
However, this will prevent all URL's with /data at the start of the URI. So if you had http://blog.sample.com/data it would also allow it to resolve without the rewrite. If this is a problem you can get more complex... after this rule add this to catch all non-dev subdomains:
RewriteCond %{HTTP_HOST} !dev\.sample\.com$ [NC]
RewriteCond %{HTTP_HOST} !www\.sample\.com$ [NC]
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,R=301]
Now if the first condition set is not met the first rule won't run, so check to make sure you're only serving dev and www up with /data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With