0

I'm trying to add a rewrite rule for an old domain test.fr.

I have placed my rule in our virtualhost in the httpd.conf file with rewrite engine on, I'm not sure why .htaccess wasn't used.

rewrite rules for test.fr

RewriteCond %{http_host} ^test.fr [NC,OR]
RewriteCond %{http_host} ^www.test.fr [NC]
RewriteRule $ http://www.test.com/france$1 [L,R=301,NC]

The issue I'm having is subsites of the domain are not transferred with the rewrite.

For example: If I go to http://www.test.fr/abc/123 it will rewrite to http://www.test.com/france/ but /abc/123 after france is left off.

Any help would be appreciated

MrWhite
  • 12,647
  • 4
  • 29
  • 41
POPEYE1716
  • 39
  • 1
  • 5
  • Where exactly have you placed these directives? Do you have other directives? (Do you have any `.htaccess` files that might _conflict_?) Ideally, you wouldn't use mod_rewrite for this anyway. Instead you would have multiple VirtualHost containers and use the `Redirect` directive instead. – MrWhite Mar 13 '18 at 16:08

1 Answers1

1

Try the following:

RewriteCond %{HTTP_HOST} ^(www\.)?test\.fr [NC]
RewriteRule ^/?(.*)$ http://www.test.com/france/$1 [L,R=301,NC]

If it isn't self-explanatory, don't hesitate to ask :)

Andreas Rogge
  • 2,853
  • 11
  • 24
  • Thank you for this, I have tried the above and am running into the same issue. Can you explain what's going on? It might help me trouble shoot. I'm not sure if it could be a caching issue on the server. – POPEYE1716 Mar 09 '18 at 16:33
  • 1
    @AndreasRogge You need to remove the `OR` flag on the _single_ `RewriteCond` directive, otherwise the `RewriteRule` will execute _unconditionally_. – MrWhite Mar 09 '18 at 22:13
  • @POPEYE1716 If you are getting the "same issue" then you are likely seeing a cached response. Or you have not restarted Apache. Clear your browser cache / restart Apache and try again (but remove that `OR` flag first). – MrWhite Mar 09 '18 at 22:16
  • Thank you for your help, I've made the changes suggested above and have restarted the App server for my redirect. Still resolving to the same where the sub-directories are left off. I'll keep researching – POPEYE1716 Mar 13 '18 at 15:22