.htaccess and '410 Gone' help please

Discussion in 'Programming' started by Byron007, Jul 16, 2011.

  1. #1
    I've around a 1000 non-existent urls indexed that I want to return a 410 and not a 404.
    The urls all have the following in common

    http://mydomain.com/[1 or 2 numbers]-[numbers and letters]
    None of the urls have a file extension.
    e.g
    http://mydomain.com/4-11055981-B001394530-Nioxin_Intensive_Therapy_Recharging_Complex_90_Count_Bottle
    http://mydomain.com/35-301188-B001UO651S-5_Pack_Premium_Reusable_LCD_Screen_Protector_with_Lint_Cleaning_Cloth_for_Apple_iPhone_3G_8GB_16GB_Accessory_Export_Packaging
    http://mydomain.com/33-Watches
    Code (markup):
    I'm trying to match any url that starts with 1 or 2 numbers, followed by a dash and followed by any combination/length of alphanumeric characters after the dash.

    I've added the following to my htaccess, but I'm still getting a 404 instead of a 410

    
    RewriteEngine On
    RewriteBase /
    # Check for HTTP/1.1 request Host header
    RewriteCond %{HTTP_HOST} .
    # Make sure the requested file does not exist
    RewriteCond %{REQUEST_FILENAME} !-f
    # Return 410-Gone for HTTP/1.1 requests for non-existent files
    RewriteRule ^[0-9]{2}-(.*)$ - [G]
    Code (markup):

    Any help appreciated
     
    Byron007, Jul 16, 2011 IP
  2. rainborick

    rainborick Well-Known Member

    Messages:
    424
    Likes Received:
    33
    Best Answers:
    0
    Trophy Points:
    120
    #2
    Just curious... What happens if you end your RewriteRule with [G=410]?
     
    rainborick, Jul 16, 2011 IP
  3. Byron007

    Byron007 Active Member

    Messages:
    174
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3
    Ok, have it working, it seems WP doesn't handle 410's
    So I had to explicitly add the path in htaccess
    ErrorDocument 404 /index.php?error=404
    ErrorDocument 410 /wp-content/themes/mytheme/410.php
    Code (markup):
    and add to my custom 410.php the following as
    <?php get_header() ?>
    Code (markup):
    didn't work

    <?php define('WP_USE_THEMES', false);
    require($_SERVER['DOCUMENT_ROOT'].'/wp-blog-header.php');
    get_header();
    ?>
    Code (markup):
    @rainborick Adding [G=410] doesn't seem to change anything. Header status code is 410 either way.

    Only issue is that my rewrite rule only works if there are 2 digits preceding the dash. If only one digit, it reverts to a 404. Off to do some more regular expression reading
     
    Byron007, Jul 16, 2011 IP
  4. Byron007

    Byron007 Active Member

    Messages:
    174
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #4
    All working perfectly now...

    # Check for HTTP/1.1 request Host header
    RewriteCond %{HTTP_HOST} .
    # Make sure the requested file does not exist
    RewriteCond %{REQUEST_FILENAME} !-f
    # Return 410-Gone for HTTP/1.1 requests for non-existent files
    RewriteRule ^[0-9]{1,2}-(.+)$ - [G]
    Code (markup):
     
    Byron007, Jul 16, 2011 IP