mod_rewrite subdomain (WITH a path) to URL

Viewed 102

Struggling with this and have already done about 30+ min of Googling.

I would like to redirect:

sub.domain.com/path1 to https://anotherdomain.com/path3
sub.domain.com/path2 to https://anotherdomain.com/path4

This code below does not work but demos my approach/thinking so far

#CLIENT 1
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mockups.domain.com$
    RewriteCond %{REQUEST_URI} ^/client1/
    RewriteRule (.*) https://xd.adobe.com/view/xxxxxxxxxxxx/ [L,R]
</IfModule>

# CLIENT 2
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^mockups.domain.com$
    RewriteCond %{REQUEST_URI} ^/client2/
    RewriteRule (.*) https://xd.adobe.com/view/xxxxxxxxxxxx/ [L,R]
</IfModule>

Can anyone sort me out on this?

1 Answers

With your shown samples only, could you please try following. Make sure you keep these rules on TOP of your .htaccess file and keep other rules below these.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mockups\.domain\.com$ [NC]
RewriteRule ^client1 https://xd.adobe.com/view/your_new_path_here [L,R=302,NE]

RewriteCond %{HTTP_HOST} ^mockups\.domain\.com$ [NC]
RewriteRule ^client2 https://xd.adobe.com/view/your_2nd_path_here [L,R=302,NE]

</IfModule>

Also please do clear your browser cache before testing your URLs.

Related