mark mark - 1 month ago 4x
Apache Configuration Question

mod_rewrite for a WordPress page doesn't seem to work

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 If someone goes to, we want to send it to 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 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})$$2 [R=301,L]

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 pages

What is the correct way to get this working?


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})/?$$1 [R=301,L]