SitePoint Sponsor

User Tag List

Results 1 to 17 of 17
  1. #1
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect host problem

    My site is hosted by Fasthosts. I have recently been trying to create a redirect from rugbyboats.co.uk/index.php to rugbyboats.co.uk/ (or vice versa - it doesn't matter) as at the moment the Googlebots etc regard this as two separate pages.

    The code I inserted into my .htaccess file was:

    Options +FollowSymLinks
    RewriteEngine 0n
    # index.php to /
    RewriteCond %{THE REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

    When uploaded it returns an Internal Server Error. I then contacted Fasthosts to be told that their Linux servers did not support 301 redirects as it is a security issue. Is this true? Or are Fasthosts unusual in this regard? And is there a workaround? I have emailed their technical support but so far they have not come back with any solution.

  2. #2
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    To which, if anyone's interested or having a similar problem, their response was:

    RewriteEngine On
    RewriteOptions inherit
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.rugbyboats.co.uk\.com$ [NC]
    RewriteRule ^(.*)$ http://rugbyboats.co.uk/$1 [L,R=301]

    Now I just need someone to tell me whether this will work or not

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Use this: (replace your url)

    # index.php to /
    # RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
    # RewriteRule ^(([^/]+/)*)index\.php$ http://www.codeegg.com/$1 [R=301,L]

    # index.html to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
    RewriteRule ^(([^/]+/)*)index\.html$ http://www.codeegg.com/$1 [R=301,L]

    Also, redirects are not security issue. I'm not sure where they pulled that statement from. lol
    TierEngine - Reliable Dedicated Servers and Colocation
    99.9% Uptime Guaranteed
    View our Dedicated Server Deals!
    Have questions? We can help. 888.233.6133 - support(at)tierengine.com

  4. #4
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tried that - the index.php version so thank you for the help.

    Sadly, it doesn't work, although unlike the earlier version, at the least the site still works. If I go to my site and add "index.php" to the url it does not redirect, and I end up with my home page. Google is definitely seeing this as a different page because rugbyboats.co.uk/ has a PR of 3 while rugbyboats.co.uk/index.php has a PR of 2.

    But then the code that Fasthosts grudgingly gave me doesn't do anything either

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2008
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suggest finding a new host then. There's no reason for blocking a 301 redirect.
    TierEngine - Reliable Dedicated Servers and Colocation
    99.9% Uptime Guaranteed
    View our Dedicated Server Deals!
    Have questions? We can help. 888.233.6133 - support(at)tierengine.com

  6. #6
    SitePoint Wizard SiberForum's Avatar
    Join Date
    Dec 2007
    Posts
    1,197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suggest you get in touch with current web host and try to find out the problem.

  7. #7
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Exactly what I'm in the process of doing. I'm shifting over to Clook after some people on here pointed me in that direction. Thanks.

  8. #8
    SitePoint Wizard SiberForum's Avatar
    Join Date
    Dec 2007
    Posts
    1,197
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good luck in solving that. Just keep us infomed if you might have any question.

  9. #9
    SitePoint Wizard ~ServerPoint~'s Avatar
    Join Date
    Nov 2007
    Posts
    1,813
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by canalboatman View Post
    Exactly what I'm in the process of doing. I'm shifting over to Clook after some people on here pointed me in that direction. Thanks.
    So how it is going now? Do you have some problems again?
    ServerPoint.com - a true hosting company since 1998
    Web Hosting, colocation,
    dedicated servers, Virtual Private Server (VPS) hosting

  10. #10
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haven't fully transferred to Clook yet but the files are uploaded. More news as it happens............

  11. #11
    SitePoint Member
    Join Date
    Jul 2010
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i'm really interested in this, can you get us posted about your host and the code you used for redirect?

    My hosting company seems to not allow this either. I want to do this for seo consideration too, but still not succeed yet.

  12. #12
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    cbm,

    I'll move this to the Apache forum as that's where mod_rewrite is discussed (and that's my excuse for not responding before this).

    Redirect is a mod_alias command which is in Apache's core. It is NOT a security issue. Neither is mod_rewrite, for that matter.

    However, since all the posters here were using mod_rewrite, I'll comment on those codes:

    1. IMHO, (almost) NEVER use the {THE_REQUEST} variable as all the ridiculous extra information (GET/POST and the HTTP version with spaces setting off the {REQUEST_FILENAME}).

    2. RewriteBase is used to UNDO a mod_alias redirect for mod_rewrite to work on the {REQUEST_URI}. IMHO, unless you're using a Redirectx statement, there is NO benefit to using RewriteBase and it will confuse the mod_rewrite locations.

    3. (.*) is the well known garbage collector (I've labeled it the EVERYTHING atom because it will match NOTHING OR EVERYTHING) but its main problem is that it will generate loops when used incorrectly.

    Specifically:
    Code:
    Options +FollowSymLinks
    # that should be in the httpd.conf
    
    RewriteEngine 0n
    # good
    
    # index.php to /
    # RewriteCond %{THE REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    # this accomplishes exactly NOTHING and
    # is likely the cause of the 500
    
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
    # other than the :kaioken: EVERYTHING :kaioken: atom,
    # the leading / in the redirection should NOT be used
    Fasthost's code:
    Code:
    RewriteEngine On
    RewriteOptions inherit
    # WHY bother?
    RewriteBase /
    # WHY bother?
    RewriteCond %{HTTP_HOST} ^www\.rugbyboats.co.uk\.com$ [NC]
    # WRONG!  I've never heard of a domain tld .co.uk.com
    # AND it's irrelevant
    RewriteRule ^(.*)$ http://rugbyboats.co.uk/$1 [L,R=301]
    # That does exactly NOTHING - WHY bother?
    Encrypted's code (PLEASE DON'T wrap code in quotes - that's what the code is for):
    Code:
    # index.php to /
    # RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.php\ HTTP/
    # RewriteRule ^(([^/]+/)*)index\.php$ http://www.codeegg.com/$1 [R=301,L]
    
    # index.html to /
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*index\.html\ HTTP/
    # Ditto the above
    RewriteRule ^(([^/]+/)*)index\.html$ http://www.codeegg.com/$1 [R=301,L]
    # hmmm, it could work to send {garbage}/index.html to {garbage}
    # I don't believe that's what the OP wants to do!
    To address the original question, though, WHY force the removal of the DirectoryIndex from a {REQUEST_URI} string? That's something which is determined by the server's configuration file. If you need to pursue this, please say so and I'll help with the code to remove the DirectoryIndex as desired.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  13. #13
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by adulti View Post
    i'm really interested in this, can you get us posted about your host and the code you used for redirect?

    My hosting company seems to not allow this either. I want to do this for seo consideration too, but still not succeed yet.
    Right, I have been up and running with Clook for about 2 weeks now and they have been extremely helpful when I ran into one or two problems with moving over my domain.

    The code I am using in the .htaccess file to redirect http://www.rugbyboats.co.uk to simply http://rugbyboats.co.uk is:

    RewriteEngine On
    RewriteOptions inherit
    RewriteBase /
    RewriteCond %{HTTP_HOST} ^www\.rugbyboats.co.uk [NC]
    RewriteRule ^(.*)$ http://rugbyboats.co.uk/$1 [L,R=301]

    It works. Now I need to work out how to adapt that code so that http://www.rugbyboats.co.uk/index.php redirects to http://.rugbyboats.co.uk/

    Thanks to you all.
    Last edited by canalboatman; Sep 14, 2010 at 09:53. Reason: url error

  14. #14
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    adulti,

    Do NOT use canalboarman's code above, use:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule .? http://example.com%{REQUEST_URI} [L,R=301]
    Reason:

    RewriteBase is designed to UNDO a mod_alias Redirect. If you don't use Redirects, you don't need this (and it can confuse YOU if it changes the directory) because it uses processor time to do NOTHING.

    RewriteOptions is designed to do, er, NOTHING! It's only option is "inherit" which is the default so, once again, you're wasting processor time to do NOTHING.

    Using the EVERYTHING atom to capture the {REQUEST_URI} string is yet another waste of time! I've used a "placeholder" regex to match zero-or-one character in the {REQUEST_URI} then direct to the preferred format of the domain name (without www in this case). Note that there is NO slash between the domain and {REQUEST_URI} because Apache 2.x includes it automatically.

    canalboatman, please take note of the above - at least if you're on a shared server (where others will be impacted by your code).
    Quote Originally Posted by canalboatman View Post
    It works. Now I need to work out how to adapt that code so that http://www.rugbyboats.co.uk/index.php redirects to http://.rugbyboats.co.uk/
    I think you did NOT mean to leave the . in your "redirection" but I'm concerned with omitting the DirectoryIndex (usually, NOT a good idea), however, this is as simple as the above, i.e., BEFORE the above, insert (after the RewriteEngine on):
    Code:
    RewriteCond %{HTTP_HOST} ^www\.rugbyboats\.co\.uk [NC]
    RewriteRule ^index\.php$ http://rugbyboats.co.uk [L,R=301]
    As usual, please note that this is for Apache 2.x; Apache 1.x must replace the ^ with ^/ and, if you're not sure which version you have, replace ^ with ^/?.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  15. #15
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    adulti,

    Do NOT use canalboarman's code above, use:
    Code:
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
    RewriteRule .? http://example.com%{REQUEST_URI} [L,R=301]
    Reason:

    RewriteBase is designed to UNDO a mod_alias Redirect. If you don't use Redirects, you don't need this (and it can confuse YOU if it changes the directory) because it uses processor time to do NOTHING.

    RewriteOptions is designed to do, er, NOTHING! It's only option is "inherit" which is the default so, once again, you're wasting processor time to do NOTHING.

    Using the EVERYTHING atom to capture the {REQUEST_URI} string is yet another waste of time! I've used a "placeholder" regex to match zero-or-one character in the {REQUEST_URI} then direct to the preferred format of the domain name (without www in this case). Note that there is NO slash between the domain and {REQUEST_URI} because Apache 2.x includes it automatically.

    canalboatman, please take note of the above - at least if you're on a shared server (where others will be impacted by your code).

    I think you did NOT mean to leave the . in your "redirection" but I'm concerned with omitting the DirectoryIndex (usually, NOT a good idea), however, this is as simple as the above, i.e., BEFORE the above, insert (after the RewriteEngine on):
    Code:
    RewriteCond %{HTTP_HOST} ^www\.rugbyboats\.co\.uk [NC]
    RewriteRule ^index\.php$ http://rugbyboats.co.uk [L,R=301]
    As usual, please note that this is for Apache 2.x; Apache 1.x must replace the ^ with ^/ and, if you're not sure which version you have, replace ^ with ^/?.

    Regards,

    DK
    You're a useful guy to know. I've taken all that on board and it works, so thank you very much.

    The "the" you refer to was only there as a definite article by the way
    Last edited by canalboatman; Sep 15, 2010 at 01:56. Reason: Fat fingers and poor grammar

  16. #16
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,650
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    cbm,

    Thanks! I'll take that as a compliment. I believe that when I tell someone NOT to use another's code, it's imperative that I fully explain my reasons. As SitePoint staff, I must consider ALL members who might read a post, not just the OP or the responder.

    I'm not sure which "the" you're referring to but please know that I mean noone any offense even though I seem to all too often. I guess old age is setting in.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  17. #17
    SitePoint Enthusiast canalboatman's Avatar
    Join Date
    Jan 2009
    Location
    On a boat in Northamptonshire
    Posts
    43
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dklynn View Post
    cbm,

    Thanks! I'll take that as a compliment. I believe that when I tell someone NOT to use another's code, it's imperative that I fully explain my reasons. As SitePoint staff, I must consider ALL members who might read a post, not just the OP or the responder.

    I'm not sure which "the" you're referring to but please know that I mean noone any offense even though I seem to all too often. I guess old age is setting in.

    Regards,

    DK
    It is a compliment, and a sincere one. And absolutely no offence taken whatsoever!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •