Kirill Ryzhkov
Kirill Ryzhkov

Reputation: 5

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?

Upvotes: 0

Views: 67

Answers (2)

user10946716
user10946716

Reputation:

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]

Upvotes: 1

RavinderSingh13
RavinderSingh13

Reputation: 133458

With your shown samples/attempts, please try following htacces rules in your htaccess file. Please place these rules at top of your file, also make sure to clear your browser cache before testing your URLs.

This will catch help.example.com OR www.help.example.com both kind of urls.

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

Upvotes: 0

Related Questions