Jasper Renema
Jasper Renema

Reputation: 143

redirect subdomain url to main domain htaccess

I've a problem i cant figure out. People access this url: http://www.sub.domain.net/action but they need to be redirect to https://www.domain.net/action/action2

I tried doing this with this line in .htaccess: Redirect http://www.sub.domain.net/action https://www.domain.net/action/action2

But it's not working. I only need this specific url to be redirected, not the entire www.sub.domain.net. Any advice?

Upvotes: 1

Views: 1879

Answers (1)

SreYash
SreYash

Reputation: 111

Try This and check if it works for you.Change Links in the code.

Put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

    # target with original URI being carried over
    RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
    RewriteRule ^ http://www.domain.com/sub%{REQUEST_URI} [NE,R=301,L]

And for 2nd part:

# static target
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/sub/zero [NE,R=301,L]

Why you didn't use jquery,javascript or php to redirect onload from one page to another?

This answer is extracted from here.

Upvotes: 2

Related Questions