0

I've been directed here by support at WPengine, but I'm not sure whether this question should be asked here or over on Overflow...

I'm using RegEx to redirect all paths and pages of a sub-domain to one page on our new website using a "domain specific" (in this case http://sub1.ourdomain) Redirect 301 ^/.* https://ourdomain/location/city, but there is one single page (eg. http://sub1.ourdomain/email_disclaimer) that I need forwarded to https://ourdomain/legal-notices. It will be the same for about 11 other sub-domains (sub1,.ourdomain sub2.ourdomain etc). How do I do this? Can I create some sort of exception to the wildcard redirect? WPengine suggested a "negative lookahead", which uses ! or something right? But, that'll only exclude it from the wildcard and not forward it elsewhere won't it?
I'm really new to RegEx and am not sure how this works and what syntax to use. I've already looked at Regex negative look-ahead is not working for mod_rewrite between different Apache versions, but am not sure what I'm looking for to help my situation.

To help clarify, the main domain has more than 700 other "ALL DOMAINS" redirects currently in place that are either 1-to-1 (Redirect 301 ^/path/to/page_01/?$ https://ourdomain/newpath/to/new-page-01) or wildcard-to-1 (Redirect 301 ^/path/to/category_01_.* https://ourdomain/newpath/to/category-01-overview)and they are working OK at the moment (when I modify my computer's HOSTS file to emulate a DNS change that hasn't been done on the live website yet). So it is the sub-domain specific wildcard-to-1 redirects I need to create a single page exception for.

Thanks in advance

Reece
  • 783
  • 2
  • 13
  • 32
  • Do `ournewsite.tld` and `ouroldsite.tld` point to the same place? Do you have other directives in your .htaccess file? – MrWhite Jul 14 '16 at 01:46
  • actually, the domain is the same. there is hundreds of other 1-to-1 redirects and quite a few wildcard-to-1 redirects. The website has been completely rebuilt with a new path structure and canonical URL scheme. We just haven't pointed the A and CNAME records away from the existing server to the new server yet – Reece Jul 14 '16 at 01:47
  • "actually, the domain is the same" - that's rather an important point, since you now have to be careful of redirect loops (why did you use two different domains in your question?). Are you currently using `Redirect`/`RedirectMatch` or `RewriteRule` directives in your existing .htaccess file? Is the `Redirect` directive you have posted intended to be a working example? (Because it cannot possibly work as intended. The `Redirect` directive does not use regex - it's prefix matching - and if you have just one domain, you're going to get a redirect loop?!) – MrWhite Jul 14 '16 at 02:08
  • Is this new redirect intended to work _with_ the "hundreds of other 1-to-1 redirects and quite a few wildcard-to-1 redirects"? Which should take priority? Your question describes a catch-all / everything redirect. – MrWhite Jul 14 '16 at 02:12
  • The exact syntax of the 700 odd redirects provided in the TXT file for WPengine to bulk upload was as written in the question (`Redirect 301 ^/path/to/old_page/?$ https://ourdomain/newpath/to/new-page`) or (`Redirect 301 ^/path/to/old_page.* https://ourdomain/newpath/to/new-page`) depending on whether it was 1-to-1 or wildcard-to-1. I used two different domains in the question because we're currently still working with the staging site on the new server which would be ourdomain.wpengine.com. But once live, the domain will be the same. – Reece Jul 14 '16 at 02:28
  • Once the TXT file was imported onto WPengine, I can see all of the redirects in their Redirect section. They apply to "ALL DOMAINS" added to the account rather than a specific domain which you can only one at a time via the Redirect section on their portal. At present, all of the redirects are working as I've tested them with both the staging domain and the real domain (after modifying the HOSTS file on my computer to emulate a DNS record change). The question is about a few of the wildcard-to-1 redirects that are working - I need to be able to exclude one URL and redirect it to elsewhere – Reece Jul 14 '16 at 02:32
  • 1
    I'm not sure that I follow... Are these directives in an Apache config file (ie. `.htaccess`)? It's just that the syntax you have provided for the `Redirect` (Apache) directive is not valid and will never match. Do you mean `RedirectMatch`? (But if you used `RedirectMatch` for the directive you posted in the question then you'll get an infinite loop if you are using just one domain?) But you say that these redirects are "provided in [a] TXT file for WPengine to bulk upload" - so what happens to these directives? Are they parsed in some way? – MrWhite Jul 14 '16 at 09:01
  • 1
    You've also tagged your question `nginx`? How is this related? Ordinarily, to "exclude one URL" you just need to make sure that this redirect is _before_ the more general wildcard redirects. More specific redirects first - but presuambly this is how your existing "1-to-1" redirects are already arranged? – MrWhite Jul 14 '16 at 09:04
  • Let us [continue this discussion in chat](http://chat.stackexchange.com/rooms/42477/discussion-between-reece-dodds-and-w3d). – Reece Jul 14 '16 at 10:11

0 Answers0