Currently I have:
Redirect 302 / http://www.example.com
Whilst I still want this redirect to happen, I don't want it to redirect them if they go to say foo.mydomain.com
or any other pages on this sub-domain.
How can I do this?
If you want to redirect your subdomain to your main domain, you can do this by editing your . htaccess file. Add the following lines of code to the file, replacing example.com with your actual domain name: RewriteEngine On RewriteCond %{HTTP_HOST} ^subdomain.example.com$ [NC] RewriteRule ^(.
Use a 301 redirect . htaccess to point an entire site to a different URL on a permanent basis. This is the most common type of redirect and is useful in most situations. In this example, we are redirecting to the "example.com" domain.
Under the Domain category, choose the Redirects menu. You'll see the Create a Redirect section. Here, you'll need to fill in which URL you want to Redirect and where you want it to Redirect To. Make sure your information is correct and choose the right connection protocol – HTTP or HTTPS.
To be more specific in that manner, you'll need to use RewriteCond / RewriteRule
rather than a simple Redirect
directive. Do a negative match (!
) for foo.mydomain.com
and perform the rewrite. You may match multiple subdomains with an OR group (foo|other1|other2)
RewriteEngine On
# Redirect anything except foo.example.com, bar.example.com
RewriteCond %{HTTP_HOST} !^(foo|bar)\.example\.com$ [NC]
# Redirect to www.example.com, preserving the URI
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=302]
If you just want to redirect to the root instead of appending the entire URI via $1
, use the same RewriteCond
and just do:
# Match and redirect everything to the root of www.example.com
RewriteRule ^. http://www.example.com/ [L,R=302]
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