Sumon Sarker
Sumon Sarker

Reputation: 2795

.htaccess doesn't redirect properly from one website to another website

I want to redirect temporarily from one URL to another URL using .htaccess

Example :

When browse from URL www.example.com, Then I want to redirect www.another-example.com. This is working good.

But don't want to redirect anywhere if browse like as www.example.com/other/path

But it is always redirecting to http://www.another-example.com if i browse like www.example.com/other/path other path.

Here is my .htaccess code

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule    ^$   app/      [L]
  RewriteRule    (.*) app/$1    [L]
  Redirect 302 "/" "http://www.another-example.com"
</IfModule>

How can I do it by modifying my .htaccess code?

Upvotes: 1

Views: 50

Answers (1)

anubhava
anubhava

Reputation: 786291

Don't use Redirect directive as it doesn't support regex and exact matching.

Use all mod_rewrite rules as in:

<IfModule mod_rewrite.c>
  RewriteEngine on

  RewriteRule ^/?$ http://www.another-example.com [L,R=301]

  RewriteRule    ^$   app/      [L]

  RewriteRule    (.*) app/$1    [L]
</IfModule>
  • ^/?$ matches only landing page for current domain.
  • Make sure to clear your browser cache or use a different browser when testing this change.

Upvotes: 1

Related Questions