Once again struggling with htaccess. I've successfully redirected the home page to my holding page with the following rule but it's not applying to child pages for some reason (mydomain.com/child-page).

<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REQUEST_URI} !/holding [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif|eot|svg|ttf|woff|css) [NC]
 RewriteRule ^(.*)$ /holding [R=302,L]

What am I doing wrong? I know it must be to do with the '^(.*)$' bit but I can;t seem to find the correct syntax.

| improve this question | | | | |

I would place the redirect inside WordPress. It lends you more control, and you don't need to worry about WP conflicting with your own .htaccess rewrites anymore.

function wpse_147377_redirect_to_holding() {
    if ( ! is_page( 'holding' ) ) {
         wp_redirect( site_url( 'holding' ) );

add_action( 'template_redirect', 'wpse_147377_redirect_to_holding' );

Place it in a "Must Use" plugin (wp-content/mu-plugins/my-plugin.php), a regular plugin, or your theme's functions.php.

| improve this answer | | | | |
  • I'm not sure about this one @TheDeadMedic: it creates a redirect loop when I use it. Should it take that condition into account automatically? Thanks. – Kevin Nugent Jun 3 '14 at 10:49
  • Ah, I assumed your holding page was outside WP - you're right, just add if ( ! is_page( 'holding' ) ) and change the hook to template_redirect (see edit). – TheDeadMedic Jun 3 '14 at 16:08

Okay, thanks for pointing me in the right direction @TheDeadMedic. I found a tidy conditional on this thread which works like a charm with the added benefit of checking to see if the user is logged in.

if ( trim( $_SERVER['REQUEST_URI'], '/' ) != 'holding' && ! is_user_logged_in() ) {
    wp_redirect( home_url( 'holding' ), 302 );
| improve this answer | | | | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.