-1
RewriteEngine on  
RewriteRule ^(.*)$ http://www.NEWfoobar.com/$1 [R=301,L]  

I have this line of code from https://stackoverflow.com/a/7578810, inside .htaccess and it currently works by migrating www.OLDfoobar.com to www.NEWfoobar.com and all its sub-directory structure just fine (intended behavior, all good)

now, how do I add additional rule that captures www.OLDfoobar.com to redirect to one specific page in www.NEWfoobar.com? say for example `www.NEWfoobar.com/welcomeToNewDomain

The [L] flag is what gets me. and btw, I'm not so sure about what the $1 is for. That can't be a regex flag for the RewriteRule pattern, yes?

ACCEPTED ANSWER

RewriteEngine on  
RewriteRule ^/?$ http://www.NEWfoobar.com/some/sub/directory [R=301,L]  
RewriteRule ^(.*)$ http://www.NEWfoobar.com/$1 [R=301,L]   
Community
  • 1
  • 1
Valkyrurr
  • 119
  • 1
  • 12
  • Yes, that's what the current script is doing fine. besides this, I'd like to implement an additional rule where it redirects from simply **olddomain** to **newdomain/sub-directory-uri** – Valkyrurr Jun 07 '16 at 09:02
  • @starkeen, my prev comment and paragraph 2 is as clear as it gets. so yes. :) – Valkyrurr Jun 07 '16 at 09:26

1 Answers1

1

You need

RewriteEngine on  
RewriteRule ^(.*)$ http://www.NEWfoobar.com/welcomeToNewDomain [R=301,L]  

The $1 meant use the first capture group which is the value between the brackets on the left.

The L in the options means stop processing the rewrite rules (ie this is the Last Rule) if the match applies.

The ^(.*)$ means:

`^` match beginning of string
`(.*)` match zero or more characters and store in capture group 1
`$` match end of string

If I've miss understood an you only want to redirect the root requests while keeping the old capture you need to add a new rule before the existing one that reads

RewriteRule ^/?$ https://www.NEWfoobar.com/welcomeToNewDomain [R=301,L]

This will match either an empty path or just /

Bob Vale
  • 18,094
  • 1
  • 42
  • 49
  • ok, got it. but it still doesn't work. the `RewriteRule` *pattern* basically means any string. so if I input `www.OLDfoobar.com/any-sub-directory-string`... given your suggested target, I'd be redirected to `http://www.NEWfoobar.com/welcomeToNewDomain/any-sub-directory-string` – Valkyrurr Jun 07 '16 at 08:55
  • @Valkyrurr No you wouldn't because I have not included the `$1` in the target rule so it would not include it. Also the key element is that the rule pattern will match any path in it's entirety. If this rule isn't working, what is the behaviour you are seeing? – Bob Vale Jun 07 '16 at 09:13
  • @Valkyrurr I may have miss understood the question slightly, see my updated answer. If you wanted `www.OLDfoobar.com/any-sub-directory-string` to redirect to a single url, use my first answer. If you want simply to add a new rewrite rule that is just `www.OLDfootbar.com` then insert my second example before your existing rewriterule – Bob Vale Jun 07 '16 at 09:18
  • Your updated answer is what I am looking for. Thank you. I misinterpret the use of `$1`, now everything is clear. – Valkyrurr Jun 07 '16 at 09:42