410 htaccess redirect – redirect html files, redirect query strings, redirect Posts or Categories

Home Forums BulletProof Security Pro 410 htaccess redirect – redirect html files, redirect query strings, redirect Posts or Categories

This topic contains 11 replies, has 3 voices, and was last updated by  brianmanee 1 year, 2 months ago.

Viewing 12 posts - 1 through 12 (of 12 total)
  • Author
    Posts
  • #23112

    AITpro Admin
    Keymaster

    A 410 Gone htaccess redirect can be used when a link/URL/URI has been permanently removed or deleted.  The primary difference between a 410 and 404 HTTP Status Code is that 410 Gone means the link/URL/URI intentionally no longer exists and 404 Not Found means that the link/URL/URI either unintentionally or intentionally no longer exists.  If a link/URL/URI has been moved to another URI then a 301 redirect should be used instead of a 410 redirect.

    Redirect a Post to the BPS 410.php template file.

    RewriteRule ^example-post-name-1/$ - [G,NC]
    RewriteRule ^example-post-name-2/$ - [G,NC]

    Redirect a Category and all Posts under that Category to the BPS 410.php template file.

    RewriteRule ^example-category-name/.* - [G,NC]

    Redirect all Requests based on a Query String: ?example-query-string to the BPS 410.php template file.

    RewriteCond %{QUERY_STRING} example-query-string
    RewriteRule .* - [G,NC]

    Redirect all .html files except for example-filename-1.html and example-filename-2.html to the BPS 410.php template file.

    RewriteRule ^example-filename-1\.html$ - [L]
    RewriteRule ^example-filename-2\.html$ - [L]
    RewriteCond %{REQUEST_URI} ^(.*)\.html [NC]
    RewriteRule ^(.*)$ - [G,NC]

    Redirect a specific .html file to the BPS 410.php template file.

    RewriteRule ^example-html-filename-1\.html$ - [G,NC]

    General Info, Notes, Setup & Usage:
    As of BPS Pro 10.4 and BPS .52 a new 410.php template file has been created and a new htaccess ErrorDocument directive has been added to the root htaccess file:  ErrorDocument 410 /wp-content/plugins/bulletproof-security/410.php
    410 Gone Requests will be logged in the BPS Security Log.  To create 410 Gone Redirect htaccess code in BPS Custom Code use the Custom Code setup steps below.

    1.  Go to the BPS htaccess File Editor page, click on the Your Current Root htaccess File tab, scroll down in your Root .htaccess file code until you see this .htaccess code below (or similar code – may look slightly different than the code below).

    # WP REWRITE LOOP START
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]

    2.  Copy your # WP REWRITE LOOP START code to this BPS Root Custom Code text box:  CUSTOM CODE WP REWRITE LOOP START
    3.  After you have copied your WP Rewrite Loop Start .htaccess code to the Custom Code text box add your particular custom 410 htaccess redirect code.  Your code should look something like the example below.
    4.  Click the Save Root Custom Code button.
    5. Go to the BPS Security Modes page and click the Root Folder BulletProof Mode Activate button.

    Examples:

    # WP REWRITE LOOP START
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    RewriteRule ^example-post-name-1/$ - [G,NC]
    RewriteRule ^example-post-name-2/$ - [G,NC]
    RewriteRule ^example-category-name/.* - [G,NC]
    RewriteRule ^example-html-filename-1\.html$ - [G,NC]

    Redirect Query Strings and URI’s|URL’s:
    Example Query Strings:

    example.com/page/30/?attachment_id=ceprgnhzjqpwfybp/
    example.com/^1572/67701.html?*session*id*key*=*session*id*val/
    # WP REWRITE LOOP START
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    
    RewriteRule ^example-post-name-1/$ - [G,NC]
    RewriteRule ^example-post-name-2/$ - [G,NC]
    RewriteRule ^example-category-name/.* - [G,NC]
    RewriteRule ^example-html-filename-1\.html$ - [G,NC]
    RewriteCond %{QUERY_STRING} attachment_id=ceprgnhzjqpwfybp
    RewriteCond %{QUERY_STRING} session(.*)id(.*)key(.*)=(.*)session(.*)id(.*)val
    RewriteRule .* - [G,NC]
    #24396

    Jose
    Participant

    Sorry, I added these two lines and I see a 500 internal error. What can I do? This extension is not working so I’d have to use ftp. /wp-content/plugins/bulletproof-security/admin/xternal/xternal.php. Is it possible deleting these two lines from Filezilla?

    RewriteRule ^page/30/?attachment_id=ceprgnhzjqpwfybp/$ - [G,NC]
    RewriteRule ^1572/67701.html?*session*id*key*=*session*id*val/$ - [G,NC]
    #24400

    AITpro Admin
    Keymaster

    The htaccess code does not look valid to me. Post the links/URL’s that you want to redirect with 410.

    http://forum.ait-pro.com/forums/topic/read-me-first-pro/#bps-pro-general-troubleshooting

    #24405

    Jose
    Participant

    They are two very old url’s (not in wordpress) about 8 years ago that I saw at Google Analytics.
    www.mysite.com/page/30/?attachment_id=ceprgnhzjqpwfybp/ and www.mysite.com/^1572/67701.html?*session*id*key*=*session*id*val/

    Now the problem is that when I delete the two .htaccess folders, I can log into the site, but when I try to click on bulletproof  500 error reappears because the two folders have been recreated again. What about deleting the two lines I added via Notepad++? I see that the root .htaccess file now is in quarantine.

    #24410

    AITpro Admin
    Keymaster

    You need to manually stop AutoRestore from restoring your root htaccess file if you are unable to use the Xternal Tools Form. Go to this folder:  /wp-content/bps-backup/autorestore/root-files/ and delete this file:  auto_.htaccess.  Then delete your root htaccess file.  If your server type needs to have an htaccess file in order for you to login to your website then download this file:  /bulletproof-security/admin/htaccess/default.htaccess and upload it to your website root folder and rename it to .htaccess.

    Since both of the 410 rules you need to create for these can be Query String conditions then this is the code you need:

    RewriteCond %{QUERY_STRING} attachment_id=ceprgnhzjqpwfybp
    RewriteCond %{QUERY_STRING} session(.*)id(.*)key(.*)=(.*)session(.*)id(.*)val
    RewriteRule .* - [G,NC]
    #24415

    Jose
    Participant

    Ok, done. It’s working now, but there are seven quarantined files that remain quarantined and I can delet them or restore them.

    auto_.htaccess				/homepages/38/dxxxxxxxxx/htdocs/wordpress/.htaccess	2015-08-08 18:23:55
    wpadmin.htaccess				/homepages/38/dxxxxxxxxx/htdocs/wordpress/wp-admin/.htaccess	2015-08-08 18:23:55
    auto_.htaccess				/homepages/38/dxxxxxxxxx/htdocs/wordpress/.htaccess	2015-08-08 18:26:03
    wpadmin.htaccess				/homepages/38/dxxxxxxxxx/htdocs/wordpress/wp-admin/.htaccess	2015-08-08 18:26:03
    auto_.htaccess				/homepages/38/dxxxxxxxxx/htdocs/wordpress/.htaccess	2015-08-08 18:35:26
    wpadmin.htaccess				/homepages/38/dxxxxxxxxx/htdocs/wordpress/wp-admin/.htaccess	2015-08-08 18:43:28
    wpadmin.htaccess				/homepages/38/dxxxxxxxxx/htdocs/wordpress/wp-admin/.htaccess	2015-08-08 18:46:40
    #24418

    AITpro Admin
    Keymaster

    Delete them.

    #24419

    Jose
    Participant

    And this code can be placed in the same place?

    #24420

    AITpro Admin
    Keymaster

    See the first post in this forum topic for how and where to add 410 Gone htaccess code.

    #24421

    Jose
    Participant

    Ok, thanks a lot again.

    #24423

    AITpro Admin
    Keymaster

    I added another example in the first post in this forum topic that shows redirecting/rewriting both Query Strings and URI’s|URL’s together/combined.

    #32912

    brianmanee
    Participant

    A 301 redirect is a permanent redirect from one URL to another. 301 redirects send site visitors and search engines to a different URL than the one they originally typed into their browser or selected from a search engine results page. These redirects also link various URLs under one umbrella so search engines rank all of the addresses based on the domain authority from inbound links. More about….Redirect a Web Page

    Brian

     

Viewing 12 posts - 1 through 12 (of 12 total)

You must be logged in to reply to this topic.