igrafix TM
igrafix TM

Reputation: 1

how to rewrite 410 .htaccess for old URL’s

I changed the entire website content and got into a script app from WordPress now I can see many 404s in the Google search console remain from the old website for 5 months in console and not deleted, one of my friends told me add 410 to old URLs, and request indexing again. so Google can delete them from the search console.

There's .htaccess code.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
  Options -Indexes
 </IfModule> 
    RewriteEngine On
RewriteCond %{HTTP_HOST} !^website.com$
RewriteRule ^(.*)$ https://website.com/$1 [R=301,L]
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

The old URLs contain bunch of links with wp-content/. Get/.. Download/.. Download-category.. Prefixes and some single URLs.

Whats the best .htaccess rewrite pattern to add 410 tag into these pages ?

Upvotes: 0

Views: 66

Answers (1)

Mahesh Thorat
Mahesh Thorat

Reputation: 1

You can try below snippet. Also check this docs

Explanation:

  1. Rewrite Conditions for Old URLs:

    • RewriteRule ^wp-content/.*$ - [R=410,L]: This returns a 410 Gone status for any URL starting with wp-content/.
    • Similar rules are added for get/, download/, and download-category/.
  2. Specific Single URLs:

    • If you have specific URLs like old-page-1/, add them as individual RewriteRule directives to return 410.
  3. Ordering of Rules:

    • The rules to return 410 are placed before the rule that routes requests to the public/ folder. This ensures that the 410 status is returned before any other routing occurs.
<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -Indexes
    </IfModule>
    
    RewriteEngine On

    # Redirect non-www to www
    RewriteCond %{HTTP_HOST} !^website.com$
    RewriteRule ^(.*)$ https://website.com/$1 [R=301,L]

    # Serve existing public folder
    RewriteRule ^(.*)$ public/$1 [L]

    # Return 410 for specific old URLs
    RewriteRule ^wp-content/.*$ - [R=410,L]
    RewriteRule ^get/.*$ - [R=410,L]
    RewriteRule ^download/.*$ - [R=410,L]
    RewriteRule ^download-category/.*$ - [R=410,L]

    # Add specific single URLs to return 410
    RewriteRule ^old-page-1/$ - [R=410,L]
    RewriteRule ^old-page-2/$ - [R=410,L]

    # Authorization rule
    RewriteCond %{HTTP:Authorization} ^(.*)
    RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
</IfModule>

Upvotes: 0

Related Questions