Miguel Stevens
Miguel Stevens

Reputation: 9230

htaccess redirect to other domain except for specific request

We're stuck on a problem regarding .htaccess. We need the website to redirect to another domain, except if the user wants the /intranet uri. Then it should just go on to index.php.

We tried the following but it's redirecting both:

RewriteEngine On
RewriteCond %{REQUEST_URI} /intranet
RewriteRule .* index.php [L]
RewriteRule .* http://google.be

We also tried this

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/intranet
RewriteRule .* http://google.be
RewriteRule .* index.php [L]

But without results. How can I proceed?

Upvotes: 1

Views: 94

Answers (1)

anubhava
anubhava

Reputation: 786339

Problem is use of REQUEST_URI variable that changes it's value to index.php in last rule. You need to use THE_REQUEST variable that doesn't get updated.

Use this code:

RewriteEngine On

RewriteCond %{THE_REQUEST} !/intranet [NC]
RewriteRule ^ http://google.be [L,R]

RewriteRule ^ index.php [L]

Upvotes: 2

Related Questions