Search code examples
apache.htaccess

Redirect from main page


I have a conditions: a) Redirect from help.example.com to example.com/support b) Redirect from other page, like help.example.com/catalog to example.com/catalog

This all I do in .htaccess file. My code redirect me only on example.com/support

RewriteCond %{HTTP_HOST}${REQUEST_URI} ^help\.example\.com/(.+)
RewriteRule ^(.+)$ example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST}${REQUEST_URI} ^help\.example\.com
RewriteRule ^(.*)$ example.com/support/ [R=301,L]

How can I resolve this problem?


Solution

  • Please try this rules for yours a - b conditions:

    a) Redirect from help.example.com to example.com/support

    RewriteCond %{HTTP_HOST} ^help\.example\.com$ [NC]
    RewriteRule ^(/?)$ https://example.com/support [R=301,L]
    

    b) Redirect from other page, like help.example.com/catalog to example.com/catalog

    RewriteCond %{HTTP_HOST} ^help\.example\.com$ [NC]
    RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]