Once i got a weird requirement from out SEO departemnt.

We we're getting some hits on a strange endpoint example.com/.../
So they asked me to do the redirect from it to home in htaccess. Turns out its not as easy as its seems.

Usually you would do this with Apache .htaccess file (or similar thing with rewrites if you're on nginx):

Redirect 301 ... /

But this time it won't work cause ... means any three symbols and you cant escape ... if it's not a regexp. I'd try to use it as a regexp, escaping all dots.

Redirect 301 ^\.\.\.$ /

This might actually work. It just looks weird as hell.

Another option is to use WordPress itself for redirect. Which is kinda wrong performance-wise but whatever.

function the_threedots_redirect() {
  global $wp;
  $current_url = home_url( $wp->request );
  if( $current_url=='https://example.com/...' ) { 
         wp_redirect( home_url() );
         exit();
  }
}
add_action( 'template_redirect', 'the_threedots_redirect' );

This way we control it on WP level. Which is kinda slower then doing it on a webserver level, but if this endpoint is accessed rarely we don't really mind that.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Menu