Jump to content

htaccess rewrite / redirect question, 2 domainnames, 1 should redirected to a subpage


horst
 Share

Recommended Posts

Hi,

I have following situation with a small local hosting company that do not give access to (common) service panels for domain administration: 
There are two existing domain names example-a.com and example-b.com. example-b.com is an old site that does not have an own webspace any longer, as its content was years old and unmaintained.

The hosting company has mapped both domain names to the same webspaces webroot directory. (at least they told so)

We have build a new site under example-a.com and it is hosted correct in the webspace. Now we want to detect all incoming from example-b.com and redirect to URL example-a.com/subpage5/

To achieve this we added the following line into the root .htaccess file:

<IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{HTTP_HOST} ^example-b\.com  [OR]
  RewriteCond %{HTTP_HOST} ^www\.example-b\.com
  RewriteRule ^(.*)$ https://www.example-a.com/subpage5/ [L,R=301]
  
  ...

But unfortunately it only redirects to the webroot (https://www.example-a.com/) and not to the /subpage5/. Does anybody has an idea why this behaves or how I can handle it better?

Link to comment
Share on other sites

Hi @horst.

RewriteCond %{HTTP_HOST} ^(www\.)?example-b\.com$ [NC] 
RewriteRule ^(.*)$ http://www.example-a.com/subpage5/$1 [L,R=301]

Maybe it's cache issue? 301 redirects are cached hard by the browser. For testing it's better to set 302 or test with browser tools open and cache disabled.

  • Like 1
Link to comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...