Welcome to the JaguarPC Community
JaguarPC
Sales: (888) 338-5261
Support: (888)-551-3050
Page 1 of 3 123 LastLast
Results 1 to 15 of 33

This is a discussion on mod_rewrite in the Shared & Semi-Dedicated forum
Ok, I am going out of my mind... All I want to do is to redirect the hostname.... from http://www.site.com/subdomain/(.*) to http://subdomain.site.com/$1 And I can't ...

  1. #1
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306

    mod_rewrite

    Ok, I am going out of my mind...


    All I want to do is to redirect the hostname....

    from

    http://www.site.com/subdomain/(.*)
    to
    http://subdomain.site.com/$1

    And I can't get this thing to do it.

    I've got the .htaccess file in the subdomain
    It apparently is being used, because the closest I got was an endless redirect loop. Every ohter time the URL remains the same in the browser.

    Stupid MSN is indexing my forum from the former I want to redirect them to the latter.

    Any suggestions?

    Thanks

  2. #2
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    Aaaaaaaaggggggghhhhhhhhhhhhhh

  3. #3
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    The solution, was just as I imagined... and maybe there's an easier way... but

    Code:
    RewriteCond %{HTTP_HOST}   !^subdomain.domain.com [NC]
    RewriteRule ^(.*)$         http://subdomain.domain.com/$1 [L,R=301]
    The problem, he says, after spending 3 hours on this......

    Was ... I have no idea.

    I thought it was because I had a comment line inbetween my rewritecond and my rewriterule.. but I just checked and it worked just fine with one in there.

  4. #4
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    This doesn't work for the case of the missing slash.

    www.domain.com/subdomain is redirected to... get this...

    subdomain.domain.com//home/<domain>/public_html/subdomain (it gives up its internal path!)


    grrrrrrrrr Where the resident 17k .htaccess guy?
    Last edited by Ron; 03-03-2005 at 01:36 AM. Reason: Removed hyperlinks inserted by the bb

  5. #5
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    Ok, this looks like it works....at the moment, anyway.

    Code:
    RewriteCond %{REQUEST_URI}   ^/subdomain$
    RewriteRule ^(.*)$         http://subdomain.domain.com/ [L,R=301]
    
    RewriteCond %{HTTP_HOST}   !^subdomain.domain.com [NC]
    RewriteRule ^(.*)$         http://subdomain.domain.com/$1 [L,R=301]
    The first set check to see if this is an un-trailing-slash'ed request for the subdomain via the incorrect path. If it is, rewrite to correct format and end.
    The second set checks for any other occurence of the imporper url, and if it finds it, rewrites to the proper address and exits.

  6. #6
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    Only two anomalies so far.... of course you can't actually have a subdirectory with the same name as the subdomain directory ie you can't have <domain>/subdomain/subdomain...

    And for some reason [NC] doesn't work (it's not in the above example) when testing against the REQUEST_URI. Very strange, and I don't see anything about it in the manual.

    Time for bed.

  7. #7
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    6,003
    Ron,

    Having fun talking to yourself? I hear Quabbin water makes people do that.

    Have you tried the more basic RedirectMatch directive? If you put this in your public_html's .htaccess I think it should solve your woes:

    RedirectMatch 301 ^/subdomain(/(.*))?$ http://subdomain.domain.com/$2

    Good luck.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  8. #8
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    That looks like it might work, too.... but I encountered a problem that was a show stopper, I had to revert.

    I have an internal rewrite to /subdomain/file.shtml. It was being rewritten as expected (ahhh as one would expect the rewrite to behave, I didn't expect the error! )

    Unfortunately, the code was depends upon the request coming from the original domain structure. When the browser displayed links, even though the url in the address showed the original domain structure, the relative links all were pointing to locations in the subdomain!!!

    heres an example.

    Someone points their browser at www.domain.com/foo/a.html
    internally, I rewrite that to /subdirectory/b.shtml
    The new rewrite directs it, (interanally also!) to subdomain.domain.com/b.shtml
    b.shtml executes php code in the subdirectory
    Page is returned with www./domain.com/foo/a.html remaining in the url text box
    links on page are relative to subdomain.domain.com, and point to non-existant locations.

    Sooooo, until I rewrite that code to execute from another directory (but it's stupid phpBB code whose code depends on a particular hierarchical structure), or figure out how to avoid having that rewrite ignore that redirect (probably a rewritecond mathcihng the filename with a do nothing and exit flag) the MSNbot can have its way with my directories.

  9. #9
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Quote Originally Posted by jason
    Ron,

    Having fun talking to yourself?
    'mod_rewrite' has that effect on you. I do it all the time - here and elsewhere. Actually, it's the best way! Talking to yourself, with a Red Dog in one hand, and a mouse in the other is a cathartic experience. Highly recommended when working with .htaccess...
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  10. #10
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    Talking to myself,,, ohh yeah! The last thing that made me erally start to blather was when I was testing the [NC] flag and found that it doesn't work on the fist Rewritecond, but does on the second Rewritecond... so I removed it.

    It was a frustrating night.

  11. #11
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,438
    I know better than to offer 'mod_rewrite' advice until I have tested it pretty thoroughly on my own. I'd hate to confuse a rule and get your site looping to itself and bog down the server or your site. It's always a "buyer beware" situation especially when advice is free, but still...

  12. #12
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    'mod_rewrite' is voodoo. If you don't believe this:

    http://www.google.com/search?sourcei...rewrite+voodoo
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  13. #13
    || $name ne 'R.Stiltskin'
    Join Date
    Jun 2003
    Location
    Tejas
    Posts
    2,438
    Quote Originally Posted by Vin DSL
    If you don't believe this:
    Oh, I know it all too well (figuratively, not literally).

    I think I have this link (Apache rewriting guide) and some of the graphics memorized. The answers are there in cryptic form. I just wince every time I need to go through it.

  14. #14
    Yeah, I know a LOT! Vin DSL's Avatar
    Join Date
    Mar 2003
    Location
    Arizona Uplands
    Posts
    10,775
    Yeah, well... I'm pretty comfortable with it these days. I can usually make it do what I want, with a little coaxing. However, it didn't come easily. It was definitely a steep learing curve - probably took a year or two before it started making sense. And, that's a long time when you're racking your brain!

    I remember the first time I discovered 'mod_rewrite'. It gave me nightmares. I'd read threads by guys doing SEO with it, and couldn't figure out what the hell they were talking about, no matter how hard I tried. Truely, there is nothing else quite like it...
    DISCLAIMER Any resemblance between the views expressed above and those of the owners and operators of this system is purely coincidental. Any resemblance between these views and my own are non-deterministic. The existence of Vin DSL is questionable. The existence of views in the absence of anyone to hold them is problematic. The existence of the reader is left as an exercise in the second-order coefficient.

    No Guts, No Story! VinDSL © 2010

  15. #15
    Ron
    Ron is offline
    Loyal Client
    Join Date
    Aug 2002
    Posts
    7,306
    I can't believe how stupid I've been about this.

    Here is the solution, I think:
    In the main directory....

    robots.txt:
    User-agent: *
    Disallow: /subdirectory

    Won't this accomplish exactly what I'm trying to do? The (good) spiders will come in and look at the robots.txt in the main directory before trying to index anything in

    domain.com/subdirectory

    and will be looking at robots.txt in the subdirectory before trying to spider anything in the

    subdomain.domain.com

    format. Won't this just sorta work for me?

    BTW I intend to place the following robots.txt files:

    in the main directory:
    User-agent: *
    Disallow: /subdirectory

    in the subdirectory:
    User-agent: *
    Disallow: /admin/
    Disallow: /images/
    Disallow: /includes/
    Disallow: /language/
    Disallow: /templates/
    Disallow: /common.php
    Disallow: /groupcp.php
    Disallow: /modcp.php
    Disallow: /login.php
    Disallow: /posting.php
    Disallow: /privmsg.php
    Disallow: /viewonline.php
    Disallow: /faq.php

    These are the complete files, i.e. there will be nothing else in them. I don't currently have any robots.txt files. I am trying to use them in conjuction with my phpBB forums.

    Any comments on these files before I shoot myself in the foot (again)?

Page 1 of 3 123 LastLast

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
  •