I'm working on Drupal7.

I want to redirect all the URl's to external domain except some. Below rewrite I have added in .htaccess file and its working fine.

RewriteCond %{REQUEST_URI} !/user.*$
RewriteCond %{REQUEST_URI} !/testurl.*$
RewriteRule .* https://abcxyz.com [R=301,L]

But then, homepage also redirecting to https://abcxyz.com

How to stop homepage redirection or how to add homepage in the exclude list like user, testurl?

I have tried below to exclude the homepage in the redirection.

RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !/index.php$
RewriteCond %{REQUEST_URI} !/homepage$

But nothing worked.

Can you help me on this please?

  • This is more an Apache question than a Drupal one, but try RewriteCond %{REQUEST_URI} !^/$ (i.e. exclude when the first character is / followed by end of line) – runswithscissors Dec 6 '19 at 19:29
  • I tried this: RewriteCond %{REQUEST_URI} !^/$ but not worked – JaSiMi Dec 9 '19 at 9:25
  • I just verified that !^/$ works on my dev Drupal 7. Perhaps there is a RewriteRule before yours that conflicts with it. Is it located immediately after the RewriteEngine on directive? Is there a RewriteRule in your <VirtualHost> or <Directory> directive? Maybe using a permanent redirect (301) before you had the correct condition causes your browser's cache to redirect without contacting the server again. Change your rewrite rule to use a temporary redirect: [R=302,L], and use incognito/private mode for testing. By the way closing all incognito mode windows should clear its cache. – runswithscissors Dec 9 '19 at 16:59
  • Got the result. In the rewriterule, insted of *, need to add + symbol which is the domain url. RewriteRule (.+) abcxyz.com [R=302,L] So, now domain, I mean homepage is not redirecting :) – JaSiMi Dec 11 '19 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.