An E-Commerce site has PDF coupons that expire after a certain date. What is the best way to handle them? I've heard allowing 404's aren't great for SEO and 301 redirects can clog up the .htaccess.

There is already a landing page generated through internal links if a coupon is expired, so ideally I would like a way to capture requests to expired assets and redirect to that page.

I'm curious, what ways are there to handle this?

  • 1
    it's probably easier to expire them if you don't allow direct access in the first place. have a script that accepts a coupon id, check if id is valid, serve associated file or custom error. – Milo Sep 14 '18 at 17:11

Are these pdfs all in a sub-directory somewhere? You could add an .htaccess file to your sub-directory root then put this as the top line.

ErrorDocument 404 /path/to/your404page

This would make it easier to manage and keep it separate from your main htaccess file.

  • While that would work, I'm curious if there is a way to do this more programmatically so the client doesn't have to reach out to me every month a coupon list expires. Edit: To answer your initial question, they are in the normal uploads directory but have a naming convention of "Print-coupon-brand.pdf", which I could throw a wildcard on. – Daniel Foust Sep 14 '18 at 16:15
  • Maybe have a cron job write an htaccess each month to those folders and hide coupons following naming convention? – Daniel Foust Sep 14 '18 at 16:24
  • What about just looking at the URL that caused the 404 and check for "Print-coupon-" or something. You could serve up a unique 404 message or redirect to a different template altogether. You could do this all within 404.php. Just thinking of ideas :) – RiddleMeThis Sep 14 '18 at 16:33
  • As far as SEO is concerned, wouldn't a 301 be better? – Daniel Foust Sep 14 '18 at 18:59
  • I would think so, you could just redirect to your landing page you have setup or maybe even the latest coupon? – RiddleMeThis Sep 14 '18 at 19:05

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.