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
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
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):