1

I have a WordPress site and a custom site and send a user from the WordPress site to the custom site when they navigate to a specific URL. Let’s say the main WP site is located at www.example.com. If someone goes to http://example.com/p/M12345, we want to send it to https://my.example.com/myexample/members/login.html?login=M12345. I thought the best way to do this would be to use mod_rewrite in the .htaccess file

I tried setting this up the main .htaccess file, but nothing seemed to work. The WP site at www.example.com uses a redirect plugin which normally takes care of this, but last week it messed up our entire site, so I am reluctant to continue using it. I would like to use the .htaccess file since this feels like the correct way to do it.

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(\/p\/)([mM]\d{5})$ https://my.example.com/myexample/members/login.html?login=$2 [R=301,L]
</IfModule>

A few things we have tried:

  • adding flags such as [NC,R=301,L], [L,QSA] and others

  • changed RewriteRule to Redirect 301 and removed the flags

  • added RewriteCond ^(/p/)$ thinking this would only occur on the example.com/p/ pages

What is the correct way to get this working?

mark
  • 183
  • 2
  • 9

1 Answers1

2

Leading slash isn't matched in .htaccess and there is en extra [ before p. Also there is no need to escape /:

RewriteEngine On
RewriteRule ^p/([mM]\d{5})/?$ https://my.example.com/myexample/members/login.html?login=$1 [R=301,L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Whoops - the "[" was a typo. That wasn't in my normal rule (i changed it to make more sense in the question than my actual use-case). Anyway- I wasn't aware that the leading slash wasn't matched. After removing that, everything works fine. Thanks! I hate it when something so small and stupid messes up your whole day. – mark Sep 06 '16 at 20:38