URL Rewrite - Is this possible?

Discussion in 'Web Design and Development' started by mathcolo, Nov 21, 2008.

  1. mathcolo macrumors 6502a

    Joined:
    Sep 14, 2008
    Location:
    Massachusetts
    #1
    Hello!

    I have been working with apache's mod_rewrite module and IIS's ISAPI_rewrite modules recently and for the first time in a while I have discovered a dilemma I just couldn't solve myself. I've looked on the documentation for rewrite mods and things, but I think maybe this idea is so strange it hasn't been documented very much before.

    Here is my dilemma: (It is rather simple)

    http://mywebsite.com/sites/site1/index.php

    In a perfect situation, would turn into this:

    http://mywebsite.com/index.php


    Is this possible with mod_rewrite/isapi_rewrite? Any help, ideas, or suggestions would be greatly appreciated.

    It is also worth noting that this same document root is being accessed by 5 different hostnames. Also, in a perfect situation, the mod_rewrite script would use HTTP_HOST to differentiate between hosts.
     
  2. sunday macrumors member

    Joined:
    May 18, 2008
    Location:
    Cypress,Texas
    #2
    Yep you can do that with mod_rewrite.
    Code:
    RewriteCond %{HTTP_HOST} ^mywebsite.com/sites/site1/index.php [NC]
    RewriteRule ^(.*)$ http://mywebsite.com/index.php$1 [L,R=301]
    
    I think that might do the trick...
     
  3. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #3
    Here's something to try out. I work with rewrites a bit. They could definitely be much more straight forward to create.
    Code:
    RewriteEngine On
    RewriteCond %{HTTP_HOST} mywebsite\.com [nocase]
    RewriteCond %{REQUEST_FILENAME} /sites/site1/index\.php
    RewriteRule /sites/site1/(index\.php)? / [last]
     
  4. mathcolo thread starter macrumors 6502a

    Joined:
    Sep 14, 2008
    Location:
    Massachusetts
    #4
    Thanks angelwatt and sunday! I merged both of those codes to create what worked for my server. I cannot believe that... it is much easier than I thought at first. :rolleyes:
     
  5. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #5
    Would you mind posting the final working version? Might help someone in the future that comes across this thread. Glad you got it working.
     
  6. JaclynMichelle macrumors newbie

    Joined:
    Nov 25, 2008
    #6
    What is the mod_rewrite/isapi_rewrite and how do you access it?
     
  7. angelwatt Moderator emeritus

    angelwatt

    Joined:
    Aug 16, 2005
    Location:
    USA
    #7

Share This Page