Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

mathcolo

macrumors 6502a
Original poster
Sep 14, 2008
860
16
Boston
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.
 
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...
 
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]
 
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:
 
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:

Would you mind posting the final working version? Might help someone in the future that comes across this thread. Glad you got it working.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.