htaccess redirect old HTML website to new HTML website

Home Forums BulletProof Security Pro htaccess redirect old HTML website to new HTML website

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #3435
    AITpro Admin
    Keymaster

    Email Question:

    Previously, you were kind enough to send me a template htaccess file for my root HTML website.

    I am having a couple of problems and wonder if you might be able to point out where my changes and your code might be clashing.

    There are two problems:

    1. The error pages are never shown. Instead if I type in something like www.example.biz/asfdjdfhhbd I get the index page. I have tried all sorts of things but can’t seem to get 404.shtml, etc. I have tried to research the web and the comments seem to boil down to a problem where RewriteRule ^index\.htm$ – [L] overwrites every option and sets the page to index.htm.

    2. Google has me listed as several different sites and I understand that I need to have a 301 redirect in order for Google to see example.co.uk, www.example.co.uk and example.biz as www.example.biz. I put the standard 301 redirect code into the htaccess file but this only results in ‘internal error 500’.

    The problem is I don’t know how to change anything without breaking it.
    If you get chance, could you please give me a few pointers.

    Cheers,
    Mark

    #3437
    AITpro Admin
    Keymaster

    1.  Do not use an shtml page it is problematic.  Use either a plain old HTML file or php file for your 404 page.  404.html or 404.php.  You can put your 404 error page anywhere you want under your website folders.  The simplest place is your website root folder and then your .htaccess ErrorDocument directive path points to the 404 file in your root website folder:  ErrorDocument 404 /404.html or ErrorDocument 404 /404.php.

    2.  Looking at the HTML htaccess files you sent me I see that you are putting your .htaccess code above the beginning of the Rewrite loop.  You do not need Options +FollowSymlinks so delete that.

    This is the beginning of the Rewrite Loop

    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.htm$ - [L]
    ...
    ...
    htaccess security code/filters in the middle of the Rewrite loop
    ...
    ...
    

    This is the end of the Rewrite Loop

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.htm [L]

    To Rewrite non-www to www and www to non-www.  NOTE:  that you are adding your code into the beginning Rewrite Loop code.

    # Rewrite non-www to www
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
    RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
    RewriteRule ^index\.htm$ - [L]
    
    # Rewrite www to non-www
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
    RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
    RewriteRule ^index\.htm$ - [L]

    Your .biz site and your .co.uk are duplicate websites and are identical, but they are completely different domain names.  From you question it looks like you want to redirect the .co.uk domain to your .biz website.

    In your root .htaccess file on your .co.uk site you need to add this code to redirect to your .biz site.  Since you are redirecting the entire site to another site you do not need to have any other .htaccess code in that .htaccess file.  Since both of these websites are HTML sites then you would not have any issues/problems with logging in if the .co.uk site was a WordPress site.

    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^olddomain.com$ [OR]
    RewriteCond %{HTTP_HOST} ^www.olddomain.com$
    RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
    #3457
    AITpro Admin
    Keymaster

    Email Reply:

    Sorry, I don’t know my login to your forum otherwise I would have responded there. First of all thanks for your input.  As I said, The main problem is that I can’t get error pages on my site (404, etc).

    On looking around the web I believe that this is because the error is captured and then a rule elsewhere replaces anything with index.htm which exists so the error is not processed.

    Anyway, I wonder if you can provide a rule that allows a 404 to be processed. Eg.

    # Rewrite Errors
    RewriteEngine On
    RewriteRule ^404.html$ - [L]

    Incidentally, I managed to get errors working on my blog www.example.biz/blog by changing

    This doesn’t work:

    ErrorDocument 403 /blog/wp-content/plugins/bulletproof-security/403.php

    This works:

    ErrorDocument 404 /blog/index.php?error=404

    Cheers,

    #3459
    AITpro Admin
    Keymaster

    You would need to Register on the BuddyPress Forum and create a login account to be able to post and reply in the BulletProof Security Forum.

    The .htaccess ErrorDocument directive is a redirect directive.  So if you use ErrorDocument 404 /404.php you have created a redirect rule for 404 errors that occur on your website.  I will provide alternative code, but if ErrorDocument is not working correctly, which it should be, then most likely whatever problem you have with your code will also occur with this code below.  The recommended and best method to handle errors is by using the htaccess ErrorDocument directive.

    Spoofing standard 404 Error handling instead of using the standard accepted coding methods/directives

    Source:  http://stackoverflow.com/questions/7630996/spoofing-a-404-not-found-error-with-htaccess

    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ (/.*)\.php
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteCond %{REQUEST_URI} !^/error\.php
    RewriteRule . - [R=404,L,NS]
    
    ErrorDocument 404 /error.php?e=404

     

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.