1

I accidently trashed my website and want to remove all indexed urls except the home page from Google and start over. Can anyone tell me how to create a .htaccess rewrite rule to return a 410 response header for all urls except the home page?

1 Answer 1

1

Try:

RewriteRule !^(?:index\.(php|html)|)$ - [L,R=410]

That will also cover index.php and index.html.

6
  • Thanks for your help. I was looking all over the place trying to find an answer to this. What about the home page? I don't want it to return a 410 error.
    – jrcollins
    Apr 30, 2014 at 7:07
  • @user2205555 since you didn't provide what your homepage was, I assumed it was "index.php" or "index.html". If it isn't then replace the index.php part of the regex with your homepage.
    – Jon Lin
    Apr 30, 2014 at 14:09
  • Sorry about the lack of info. It's a Wordpress site, so the homepage is mydomain.com. I just want to make sure I get it right.
    – jrcollins
    Apr 30, 2014 at 22:44
  • @user2205555 the / means there's no URI, and that's covered by the optional "index.php". Apache will internally route / to /index.php, which is also handled. Did you try the code?
    – Jon Lin
    Apr 30, 2014 at 23:11
  • I tried it but I'm still getting a 404. Where exactly should I put the code you gave me? Also, is that meant to be a forward slash or backslash?
    – jrcollins
    May 1, 2014 at 6:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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