SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast Hervard's Avatar
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Exclamation Add-on Domains Directories Without Trailing Slash Problem (mod_rewrite to Fix?)

    I have a virtual host account on an Apache server, with support for mod_rewriting, and mod_rewrites do work as they should.

    Here's my situation:

    My main domain name is apples.com (for example).

    I have a sub-domain called oranges.apples.com.

    I have an add-on domain name, oranges.com, which is assigned to oranges.apples.com.

    When someone goes to oranges.com, the URL address stays as oranges.com, and its content is the as if someone went to oranges.apples.com.

    Within oranges.apples.com there is a directory called juice, which would be shown as oranges.apples.com/juice, or oranges.com/juice.

    When someone accesses http://oranges.com/juice/ (note the trailing slash), the URL address stays as the user typed it.

    However, when someone accesses http://oranges.com/juice (without the trailing slash), the URL address becomes http://oranges.apples.com/juice/, which is not what I want to have happen. I would like to just have the address add on the trailing slash, and not put in apples.com at all.

    What mod_rewrite code might solve this problem? Any help would be greatly appreciated.

  2. #2
    FreeBSD The Power to Serve silver trophy pippo's Avatar
    Join Date
    Jul 2001
    Location
    Italy
    Posts
    4,514
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I know this issue has been addressed some times ago (if you do a search under my user name and with the key word "mod_dir" or "mod_dir.c" you should find it).

    I think I also posted a trick to do it.

    The solution is to test if that URI without the trailing slash is a directory.
    If it's a directory you will have to make an external redirection, 30x, to the URI containing the trailing slash.

    I'm a bit busy, as always recently , but if you can't find anything doing a search or if you won't receive any answer by tomorrow morning (GMT+1) I will take a look to this issue and I will post my way to do it by using mod_rewrite.


    Mr Andrea
    Former Hosting Team Advisor
    Former Advisor of '03

  3. #3
    SitePoint Enthusiast Hervard's Avatar
    Join Date
    Jul 2004
    Location
    New Zealand
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Thank you very much for pointing me in the right direction, pippo. I ended up using your first example from http://www.sitepoint.com/forums/showthread.php?t=131273

    After trying some things out for a while, here's what I made work (I kept in your comments):

    Code:
    RewriteEngine On
    Options +FollowSymlinks
    
    # The URI doesn't end with a trailing slash
    # so it *could* be a directory
    RewriteCond %{REQUEST_URI} !/$
    
    # Adding the trailing slash the directory does exist!
    RewriteCond %{REQUEST_FILENAME}/ -d
    
    # Do not redirect to apples.com
    # and make an external redirection adding the trailing slash!
    RewriteRule !^apples.com http://%{HTTP_HOST}%{REQUEST_URI}/ [R,L]
    This works perfectly. When someone goes to http://oranges.com/juice they then get redirected to http://oranges.com/juice/ without any trouble.

    Thanks very much for your help!


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
  •