Might sound confusing, but what I want to achieve is this:

  1. If the user visits:

    www.mydomain.com (with or without www.)

    transfer them to:


  2. At the same time, I want to achieve this:

    If they visit:

    www.domain.com/about-us (with or without www.)

    transfer them to:


What I have so far is this:

<IfModule mod_rewrite.c>
    RewriteEngine On

    # To redirect all users to HTTPS 
     RewriteCond %{HTTP:X-Forwarded-Proto} !https
     RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    # Redirects all www to non-www
     RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
     RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

     RewriteBase /
     RewriteCond %{HTTP_HOST} (^www.)?mydomain.com/?$ [NC]
     RewriteRule ^(.*)$ https://myotherdomain.com/$1 [R=301,L]

Which works with point #2

Any help is appreciated!

RewriteCond %{HTTP_HOST} (^www.)?mydomain.com/?$ [NC]
RewriteRule ^(.*)$ https://myotherdomain.com/$1 [R=301,L]

Which works with point #2

But the "problem" with this is that it redirects everything, not just /about-us, which is what you've stated as the requirements for point #2.

(^www.)?mydomain.com/?$ - You've put the start-of-string anchor (^) in the wrong place. This will match any hostname that simply ends in "mydomain.com" (including any subdomains and domains that share the same suffix). The Host header never ends in a slash, so the /? at the end is superfluous.

(And the RewriteBase directive is not required here.)

You would need to do something like the following instead, before your existing directives, at the top of your .htaccess file:

# Redirect "/" (document root) only
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com [NC]
RewriteRule ^$ https://www.myotherdomain.com/welcome-old-users [R=302,L]

# Redirect "/about-us" only
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com [NC]
RewriteRule ^about-us$ https://www.myotherdomain.com/$0 [R=302,L]

You will need to clear your cache before testing. Test with 302 (temporary) redirects and ensure it is working before changing to a 301 (permanent) redirect - if that is the intention.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.