Announcement

Collapse
No announcement yet.

help with Mod_rewrite for .htaccess

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • help with Mod_rewrite for .htaccess

    I have found how to ftp transfer a .htaccess without the website crashing! I am using FileZiller which shows all the files unlike FTP Surfer which I think is a bit outdated now.!

    I have tried this mod-rewrite inside a .htaccess file in my root:
    RewriteEngine On
    RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm
    and it works a treat.

    But how do I add further re directs such as?
    RewriteEngine On
    RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm
    RewriteRule ^new_home_warranty.htm$ /nhbc-home-warranty.htm as an example?

    I would also like to know how to re dircet something in a folder like:
    Old URL:
    www.bnh.co.uk/homes/adverts/index.php to
    New URL:
    www.bnh.co.uk/homes/index.php
    I think it may be more to do with where the .htaccess file for this is put rather than the code.

    I would also like to know what the mod_rewrite code would be fior an error 404 re direct to a custom error page.

    I do hope someone will be able to help me and any help would be much appreciated.
    Last edited by Jasperweb; 02-14-2013, 06:18 AM.

  • #2
    Bit of help please?

    Can siomeone answer my question please, I really need a push in the right direction.

    I give at least an hour a day on a new homes snagging forum, helping people with issues concerning new homes - a subject I do know lots about.

    I dont post on here as I know next to nothing about coding hence needing some help!

    Comment


    • #3
      You just add more if you want more, but you only turn it on once.
      Code:
      RewriteEngine On
      RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm
      RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm
      RewriteRule ^new_home_warranty.htm$ /nhbc-home-warranty.htm
      
      /* Redirects */
      Redirect /homes/adverts/index.php www.brand-newhomes.co.uk/homes/index.php
      You can have as many lines as you want

      For special error documents, add this to the end of your list
      Code:
      ErrorDocument 401 /errorbot.php?error=401
      ErrorDocument 403 /errorbot.php?error=403
      ErrorDocument 404 /errorbot.php?error=404
      ErrorDocument 500 /errorbot.php?error=500
      The errorbot.php can be normal html pages.
      Last edited by scoutt; 02-09-2013, 01:21 PM.
      Have a Script or Snippet you want to share?

      WWW Standards: HTML 4.01,
      HTML 5, CSS2.1, CSS3, XHTML 1.0
      PHP Standards: PHP Standards

      Comment


      • #4
        First of all thank you for your reply.

        I had this in my .htaccess file

        RewriteEngine on
        RewriteCond %{HTTP_HOST} !^www\.brand-newhomes\.co\.uk
        RewriteRule (.*) http://www.brand-newhomes.co.uk/$1 [R=301,L]
        RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm
        RewriteRule ^new_home_DIY_snaglist_internal.htm$ /new_home_diy_snaglist_internal.htm
        RewriteRule ^new_home_DIY_snaglist_external.htm$ /new_home_diy_snaglist_external.htm
        RewriteRule ^new_home_DIY_snagging_guidance.htm$ /new_home_diy_snagging_guidance.htm
        RewriteCond %{THE_REQUEST} ^.*/index\.htm
        RewriteRule ^(.*)index.htm$ http://www.brand-newhomes.co.uk/$1 [R=301,L]

        /* Redirects */
        Redirect /forum/smf/index.php www.bnh.co.uk/nhbc-new-home-warranty.htm


        [code]
        ErrorDocument 404 /404 re-direct.htm?error=404
        [/php]


        The black bits work fine but after adding the blue code you suggested the website crashes giving:

        Internal Server Error
        The server encountered an internal error or misconfiguration and was unable to complete your request.

        Please contact the server administrator, root@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error.

        More information about this error may be available in the server error log.


        The .htaccess file can only contain mod_rewrite code for my server apparently!
        Last edited by Jasperweb; 02-14-2013, 06:19 AM.

        Comment


        • #5
          hope you didn't add this in there

          [/php]

          Its not part of it. Please re-read my post, I have fixed the text
          Have a Script or Snippet you want to share?

          WWW Standards: HTML 4.01,
          HTML 5, CSS2.1, CSS3, XHTML 1.0
          PHP Standards: PHP Standards

          Comment


          • #6
            Thank you for your help:
            I have managed to get it to work using this:
            RewriteEngine on
            RewriteCond %{HTTP_HOST} !^www\.brand-newhomes\.co\.uk
            RewriteRule (.*) http://www.brand-newhomes.co.uk/$1 [R=301,L]
            RewriteRule ^brand_new_home_warranty.htm$ /nhbc-new-home-warranty.htm
            RewriteRule ^(.*)index.htm$ http://www.brand-newhomes.co.uk/$1 [R=301,L]
            ErrorDocument 404 /404-re-direct.htm

            Comment

            Working...
            X