Xepher.Net Forums

Xepher.net => Hosting Q&A => Topic started by: Databits on August 31, 2005, 08:44:33 PM

Title: Subdomains using server side .htaccess files
Post by: Databits on August 31, 2005, 08:44:33 PM
Xepher, currently I'm working on a new version of my website. I know that under the kanar website, we were capable of setting up the subdomains such as test.kanar.org, to point to another directory which we called "test.kanar.org" without using things like php.

Now what I want to know, is if it is possible for me to write a server script (.htaccess) file in my public_html directory that would do just that.

I.E.

test.databits.cc would be directed to the public_html/test.databits.cc directory, as www.databits.cc or databits.cc would be directed to the public_html/databits.cc folder.

The only thing I've ever used .htaccess for was to prevent indexing of folders and set 404 error pages. So I'm not even sure if this is possible, but would rather not dabble in anything that could potentially screw something up for me or you.
Title: Subdomains using server side .htaccess files
Post by: Xepher on August 31, 2005, 09:40:24 PM
It is doable... what you're looking for is called "ModRewrite, the swiss army knife of URL manipulation." It's a built in part of apache, and so it's already running on the server. You just have to put the proper directives in the .htaccess configs. That's the hard part, as, from the offical documentation...
QuoteThe great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.

    -- Brian Behlendorf
    Apache Group
Also, like the docs say "it's voodoo... cool voodoo, but still voodoo"

As such, I'm simply going to point you at some useful docs, and then wish you the best of luck.

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Title: Subdomains using server side .htaccess files
Post by: Databits on August 31, 2005, 10:18:48 PM
Awesome, I'll look into it. I've been searching for awhile for the method to do this, but just as I was starting to run across the rewrite stuff I checked back here and found this. Thanks!
Title: Subdomains using server side .htaccess files
Post by: Databits on September 01, 2005, 02:51:13 AM
I'm realizing I'm not getting any results... it is built into apache, but it's disabled by default. I'm not sure if it's enabled because I get absolutely no results when using any sort of RewriteEngine on code in the .htaccess file. Other things work however, such as Options -Indexes.

EDIT: Actually, I didn't have the DNS being managed by xepher.net, it was being hosted by enic.cc. I've changed it so that the databits.cc domain is managed by your server, but I need the MX record on my domain to be mx.enic.cc to continue to use the email forwarding I have set up.

Only problem is, I was unable to simply list xepher.net as a name server, instead I needed to use xepher.net and ns2.xepher.net (I had ns1.xepher.net in there too, all from a previous configuration).
Title: Subdomains using server side .htaccess files
Post by: Xepher on September 01, 2005, 03:55:06 AM
I don't have a config set up for the nameserver to point the site here, but the mailserver somewhere else. If you use the XN nameservers, then everything is going to point here, and all email to that domain will dump into your account here. If you use someone else... well then you need to tell all of those various subdomains to point here as well. So long as the domain name resolves to this server (and is *.databits.cc) it'll go to your account, from which the .htaccess things can be used to send it to a specific site.

Oh, and if you want to use XN for nameservers, it's ns1.xepher.net and ns2.xepher.net. Please don't use JUST "xepher.net"
Title: Subdomains using server side .htaccess files
Post by: Databits on September 01, 2005, 07:04:18 PM
Ok, I have enic handling the dns again, I finally got it to work. Turned out that I was using far overcomplicated examples to do what I needed to do. Damn those people and their "examples", I used what I learned in my Linux class instead.


EDIT: Just in case anyone else is looking for a similar solution I'm going to show the code I used and explain things a little bit for you all.

.htaccess
QuoteRewriteEngine On
RewriteCond $1 !/$
RewriteCond $1 !.
RewriteRule ^(.+)$ /$1/ [R=301,L]
RewriteCond %{REQUEST_URI} !^/.*
RewriteCond %{HTTP_HOST} !^www.domainname.com [NC]
RewriteCond %{HTTP_HOST} !^domainname.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).domainname.com
RewriteCond /home//public_html/%1 -d
RewriteRule (.*) /%1/$1 [L]
What this code essentially does is redirects the document root to another folder based on whatever sub-domain you give. Multiple conditions automatically determine if the folder exists or not, and make sure that it's not a root domain I.E. www.domainname.com or domainname.com.

For example, the default root directory located under a username on this server is /home//public_html/. Using my domain as an example, both http://www.databits.cc/ and http://databits.cc/ point to this location.

Now when a user enters something as an alternate sub-domain, or something like subdomain.domainname.com the code above will parse out the subdomain part, check to see if /home//public_html/subdomain/ exists, then if it does redirect the document root to that location instead. As demonstrated using my site, when you goto http://test.databits.cc/ you will get the same thing as if you went to http://databits.cc/test.databits.cc/, http://www.databits.cc/test.databits.cc/, or even http://databits.xepher.net/test.databits.cc/. But more seemlessly to the user (my folder is actually named test.databits.cc, not just test).

Now, to explain some of this code in more detail...

QuoteLINE 1
QuoteRewriteEngine On
The first line for the code is required for the rest to work. It effectively does exactly as it says, turns on the rewrite engine.
QuoteLINES 2-4
QuoteRewriteCond $1 !/$
RewriteCond $1 !.
RewriteRule ^(.+)$ /$1/ [R=301,L]
These lines of code check for and add a trailing slash to the URL if it doesn't exist.
QuoteLINES 5-9
QuoteRewriteCond %{REQUEST_URI} !^/.*
RewriteCond %{HTTP_HOST} !^www.domainname.com [NC]
RewriteCond %{HTTP_HOST} !^domainname.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).domainname.com
RewriteCond /home//public_html/%1 -d
These lines are the conditions list. All the conditions must be met before the following rewrite will occur. The first and second lines here check to make sure that the domain is not a root domain I.E. domainname.com or www.domainname.com. The following line parses out the subdomain from the front of the domain. The last line checks to see if a folder matching the subdomains name exists.
QuoteLINE 10
QuoteRewriteRule (.*) /%1/$1 [L]
This is the line that does the domain rewrite. If all the previous conditions were met, this line will redirect the document root to the specified subdomain's folder.
With a little revision, this code could be changed along with the directory structure under your public_html folder to prevent users from doing things like accessing subdomains from inside another subdomain. An issue I'm not addressing right now.

NOTE: If anyone is looking to do something similar and runs into issues, I have no problem helping you out. All you gotta do is ask. ;)
Title: Subdomains using server side .htaccess files
Post by: fesworks on March 02, 2007, 03:12:42 PM
So I just download the Unix version ( http://httpd.apache.org/download.cgi )  and I change the .htaccess configs through that? or is it already on the site somewhere because you said it's preinstalled on the server?
Title: Subdomains using server side .htaccess files
Post by: Xepher on March 02, 2007, 09:32:45 PM
WHAT? No no no... you don't have to download an entire webserver! (Or anything for that matter.) You just have to create a file named .htaccess  in your public_html folder with the proper rules. It's just a plain text config file, that's all. Make it with anything from notepad to nano.

Try this code.
RewriteCond %{HTTP_HOST}   ^.*.fesandernst.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         /home/fesworks/public_html/fesandernst/$1 [L]

RewriteCond %{HTTP_HOST}   ^.*.fesworks.com [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteRule ^/(.*)         /home/fesworks/public_html/fesworks/$1 [L]
That make sense? It'll look for the domainname, and if it matches, it'll go to a subdirectory (transparently to the user.) I think that's what you want. Code isn't actually tested, so if it doesn't work, let me know and I can take a look at it in action and try and tweak it.

See this for some other examples. http://httpd.apache.org/docs/2.0/rewrite/rewrite_guide.html
Title: Subdomains using server side .htaccess files
Post by: fesworks on March 03, 2007, 03:20:26 AM
On this thread you gave me a different code:
https://xepher.net/forum/viewtopic.php?id=455&p=2

it had an "R" in there with the "L"

Well, I'll give these a shot.
Title: Subdomains using server side .htaccess files
Post by: Xepher on March 04, 2007, 09:52:58 PM
The "R" does a redirect... that is sends the browser a message saying "this moved to this new address, go there" without the R, it does it behind the scenes, so to speak, and serves the new file, even though the browser still thinks it's at the old address. The "R" thing you'd do if you want something like "fesworks.xepher.net" to always go to just "fesworks.com" so everyone gets used to going to the same place. On the other hand, hosting a SEPERATE subdomain, you probably want it to look like to seperate websites, not tell the browser "I know you asked for ardra.com, but go to http://fesworks.com/adra/ to find what you're looking for." Make sense? (Note that when I gave you the code in that other thread, I thought you were doing something quite different than what you're asking here.)
Title: Subdomains using server side .htaccess files
Post by: fesworks on March 05, 2007, 02:10:16 PM
Yea, in the other thread I ended up going through all my pages and changing the links from "home.php" to "index.php"

Now I am going to try and get "fesworks.com" to point to http://fesworks.xepher.net/TCSS.htm for the review site, but I'm going to try the code it with the domain I already have here before I ask to have "fesworks.com" moved here too... just to make sure I get the coding all right.
Title: Subdomains using server side .htaccess files
Post by: Xepher on March 05, 2007, 11:51:20 PM
Okay, well, if you get something in place and it's not working, let me know precisely what's supposed to redirect to what, and I can take a look at it if you want.
Title: Subdomains using server side .htaccess files
Post by: fesworks on March 06, 2007, 01:29:52 AM
well thank you. I hate to seem like a wet baby coder about things lately, but I'll try this out on my own first in the next few weeks :D
Title: Re: Subdomains using server side .htaccess files
Post by: fesworks on September 11, 2007, 02:00:05 AM
I never did try what you suggested... mostly because I never got "fesworks.com" moved to Xepher... it still redirects from Yahoo.

I'd like to make "fesworks.com" point to my account just like you have "fesandernst.com" point to my account.

I'm also planning on getting a domain for that Jenny Everywhere archive I've told you about. I may have to use the version that's on my fesworks.xepher account. I have a co-project with Strip Foght coming soon.



So let me get this straight... if I get "http://theshifterarchive.com" (may or may not be the only, or final domain) on the xepher nameservers, it will go to http://fesworks.xepher.net .... and if I want it to point to, say, http://fesworks.xepher.net/SAP instead, I'd have to input this code you mentioned into the .htaccess of my public_html folder (the base folder right?)?

Also, if that's true, would it work in the same manner if it were the base of the subfolder?

like right now, http://fesworks.xepher.net is also fesandernst.com.... and http://fesworks.xepher.net/SAP is the same as http://fesandernst.com/SAP

and so on for all files and folders.

using this .htaccess code, would it act the same way for the sub folder?

Like I think you are saying that http://fesworks.xepher.net/SAP will become http://theshifterarchive.com .... right?

well would http://fesworks.xepher.net/SAP/STORIES also be http://theshifterarchive.com/STORIES as well? and so on for each file and subfolder of /SAP/ ?


basically I'm seeing if I can host it proper on my account now, and move things over to a new account (if my application for it gets approved of course) without loss to permalinks?
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on September 11, 2007, 02:20:39 AM
Okay... I think I get what you said, and you seem to be correct. You should be able to effectively do any of what you want using the rewrite stuff. To put it (hopefully) simply... the rewrite stuff let's you just set a rule to say "when you see this change it to that" but in really complicated ways. Thus, it's no problem to take every case of "http://siteb.com/XXXX/stuff" and change it to "http://sitea.com/stuff" Well, that's not the best example, the better way of viewing it is to say, when you see a thing starting with "http://siteb.com/" serve it from "/home/fesworks/public_html/siteb/" which means that "http://siteb.com/stuff/things" serves the files from "/home/fesworks/public_html/siteb/stuff/things" which is ALSO the same as "http://fesworks.com/siteb/stuff/things" etc.

Like I said earlier, you can make anything work however you want... it's just a matter of  how complicated the rules get. Also, don't feel bad about the confusion. mod_rewrite uses regular expressions... possibly the most complicated thing in computing/coding. I mean, even the official documentation admits it's voodoo!

Quote
(From http://httpd.apache.org/docs/2.0/rewrite/ )

"The great thing about mod_rewrite is it gives you all the configurability and flexibility of Sendmail. The downside to mod_rewrite is that it gives you all the configurability and flexibility of Sendmail.''
-- Brian Behlendorf, Apache Group

"Despite the tons of examples and docs, mod_rewrite is voodoo. Damned cool voodoo, but still voodoo. ''
-- Brian Moore, bem@news.cmc.net

Welcome to mod_rewrite, the Swiss Army Knife of URL manipulation!
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on September 11, 2007, 05:09:28 AM
As much for my own notes as well as to help other people... working code for a .htaccess file in public_html, linking a particular folder to a particular subdomain.


RewriteEngine On
RewriteCond %{HTTP_HOST}   (.*)fesworks\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/TCSS/(.*)
RewriteRule ^(.*)         /TCSS/$1 [L]


That makes the fesworks.com domain work as the public_html/TCSS/ folder.
Title: Re: Subdomains using server side .htaccess files
Post by: fesworks on September 11, 2007, 05:11:04 PM
Sounds good :D Thanks again :D

Also, hate to bother you again, but can you make "theshifterarchive.com" apart of the Xepher namesevers please? I just bought it this morning :)
Title: Re: Subdomains using server side .htaccess files
Post by: jekkal on September 12, 2007, 03:31:36 AM
Regular Expressions ARE VooDoo.

How else do you explain Computational Linguistics?!
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on September 12, 2007, 05:15:04 AM
Fes: Done. Switch the nameservers and it should work.

Jekkal:
(http://imgs.xkcd.com/comics/computational_linguists.png)
(From http://xkcd.com/114/ )
Title: Re: Subdomains using server side .htaccess files
Post by: fesworks on September 12, 2007, 01:49:57 PM
Awesome! Thanks much! :D
Title: Re: Subdomains using server side .htaccess files
Post by: Miluette on April 13, 2008, 05:14:11 AM
Old topic REVIVAL!

So today I've been trying to figure out how to do subdomains for my folders, since apparently it's not as easy as creating one at godaddy and typing in the URL of your desired folder. Grr! Things are never that simple!

For example, I would like

http://senshuu.com/ai/

to also show up like

http://ai.senshuu.com

I'd also like to have maybe more than one subdomain leading to the same folder. They would remain the same as you navigate the site too, like ai.senshuu.com/art.php would still show up that way instead of reverting, if I'm wording it right.

Everything I've found so far (like THIS (http://ask.metafilter.com/22852/Redirecting-subdomains-with-modrewrite)) hasn't really worked, but I might have gone about it the wrong way--evidently all the code has to be in the htaccess file in the root folder?

By the way, I just happily used this thread to link a folder to my new domain name. Yay! Now -this- should be simple, but it's a little opposite...

One other thing: Whenever anyone goes to my domain name, like senshuu.com/ai/ for instance, and leaves off the final forward-slash, the url always changes back to the Xepher subdomain address, in this case millennium.xepher.net/ai, which is kind of awkward since people don't always put in those last forwardslashes.

I know why this happens now, but need to know how to fix it. I'm gonna paste what Xepher said here to remember:

"This is again, something you can fix yourself with the same sort of mod_rewrite stuff I mentioned above. I, unfortunately, don't have an example of doing this specifically, but I know it's possible. You can basically make your own custom rule to tell the server to look for folders and add the slash, but extend it so it remembers which domain people used the first time."

I'm getting into some pretty complex code stuff. I never thought I'd even have to touch it. But, I like having things a certain way. <3

Preemptive thanks!
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on April 13, 2008, 07:58:07 AM
It's 3am, and I'm drunk, and I'm trying this from memory and with minimal testing, but something like this might work...


RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^(.+[^/])$           http://%{HTTP_HOST}/$1/  [R]


Which should, I believe, check the requested filename, and if it's a directory, send the user to a new URL with the trailing slash added, using whatever host/domain name they used to start with.

Subdomains going to other folders should be just like the example at the top of page 2 here, except you extend it to the subdomain level...


RewriteCond %{HTTP_HOST}   ai\.senshuu\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/ai/(.*)
RewriteRule ^(.*)         /ai/$1 [L]


That "[L]" part (the "last rule" flag) may need to be removed depending on the order of things in your .htaccess file. It basically says "when this line gets used, stop any further URL rewrites" so if you've got a bunch of stuff in your .htaccess file, you don't want that until the last line usually. (Or at least the last line that should be logically used from any given entry point... if that makes sense.)


On another note... why do I only seem motivated/able to do code/technical problems when drunk on a weekend? :-P



EDIT: I know it's pretty technical, but most everything I know (except regular expression in general), I learned from the official apache documentation. http://httpd.apache.org/docs/2.2/rewrite/
Title: Re: Subdomains using server side .htaccess files
Post by: Miluette on April 13, 2008, 08:51:47 AM
Wahahaha, it works, it all works... beautiful. Thank you so much. ;x;

There are only two questions remaining for me!

(1) How you make a subdomain redirect to a file--in this case, senshuu.com/main.php (which I want to be millennium.senshuu.com ... really weird how I set it up the first go-round, in retrospect), if that's possible.
(2) The following didn't quite work, although it might be my fatigue playing into my understanding of things right now:

RewriteCond %{HTTP_HOST}   ai\.jessicacantlope\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/ai/(.*)
RewriteRule ^(.*)         /ai/$1


When I put that in it just redirects to jessicacantlope.com when I thought it would go back to the other Ai site... unless it's the way I have the stuff with Jessicacantlope.com, yeah that probably has something to do with it! lol I'm out of it.

But I'm in such a coding mood. It always happens late night when I should be doing other things. (Not drunk though... alcohol doesn't like me.)
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on April 13, 2008, 09:20:07 AM
Okay... even drunker now, so take with lots of salt... but I think you've probably got an [L] flag somewhere in the jessicacantlope.com stuff, so it's hitting the first thing in the file and ignoring the rest. Keep in mind, with regular expressions the "(.*)" thing is a wild card, and matches anything, so if you have "(.*)jessicacantlope\.com" and "ai\.jessicacantlope\.com" in different rulesets, you need to put the more exact/specific AI one first, else the other one (with the wildcard) will match either case. Alternately, you may try getting rid of the [L] flag on the wildcard one, see if it passes on through and matches the next like you'd expect. I'm not exactly sure on the rules of precedence for this stuff, but... well, the general problem is just something like that.


As for a subdomain going to a specific file... that's just a specific case of the same directory level redirect we've already done.

Try:

RewriteCond %{HTTP_HOST}   millennium\.senshuu\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/main.php
RewriteRule ^/         /main.php
Title: Re: Subdomains using server side .htaccess files
Post by: Miluette on April 13, 2008, 09:50:20 AM
So I rearranged things with my first issue and then the address went to my main 404 page...lol. Then I realized it must be trying to go to /portfolio/ai/, which doesn't exist.
With all this fancy coding I'm not sure exactly how to fix it. I just tried and got a 500 error, lol.

Also, the main.php subdomain redirect doesn't work. I hope it's not another order issue.

Wow, I've spent more time on this than I thought today (along the way I've been cleaning up code here and there). I need to sleep or something lol.
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on April 13, 2008, 12:14:17 PM
All the snippits I've given you work by themselves and alone... I've never tried putting them all together though, so I'm not sure how they work together. You may just have to play with it a bit, but if you can't figure it out, I'll try and give it a go next time I have some time (and am sober... right now it's saturday night/sunday morning and OMG 7am.)
Title: Re: Subdomains using server side .htaccess files
Post by: Miluette on April 13, 2008, 10:37:27 PM
This is what my main .htaccess file looks like right now:


ErrorDocument 404 http://www.senshuu.com/404.php

RewriteCond    %{REQUEST_FILENAME}  -d
RewriteRule    ^(.+[^/])$           http://%{HTTP_HOST}/$1/  [R]

RewriteCond %{HTTP_HOST}   ai\.jessicacantlope\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/ai/(.*)
RewriteRule ^(.*)         /ai/$1

RewriteEngine On
RewriteCond %{HTTP_HOST}   (.*)jessicacantlope\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/portfolio/(.*)
RewriteRule ^(.*)         /portfolio/$1 [L]

RewriteCond %{HTTP_HOST}   millennium\.senshuu\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/main.php
RewriteRule ^/         /main.php

RewriteCond %{HTTP_HOST}   ai\.senshuu\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/ai/(.*)
RewriteRule ^(.*)         /ai/$1

RewriteCond %{HTTP_HOST}   lf\.senshuu\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/lf/(.*)
RewriteRule ^(.*)         /lf/$1

RewriteCond %{HTTP_HOST}   lovefeast\.senshuu\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/lf/(.*)
RewriteRule ^(.*)         /lf/$1

RewriteCond %{HTTP_HOST}   portfolio\.senshuu\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/portfolio/(.*)
RewriteRule ^(.*)         /portfolio/$1

RewriteCond %{HTTP_HOST}   portfolio\.jessicacantlope\.com$ [NC]
RewriteCond %{HTTP_HOST}   !^$
RewriteCond %{REQUEST_URI}  !^/portfolio/(.*)
RewriteRule ^(.*)         /portfolio/$1 [L]


They all work except for the two I mentioned, ai.jessicacantlope.com and millennium.senshuu.com. D:
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on April 14, 2008, 02:33:05 AM
I edited your .htaccess file to fix things, as I needed to test, since I wasn't really sure what to do.

Basically, it was partly like I said, the [L] flags and the order. I had to change the wildcard jessica... entry to be ^(www\.)?jessicacantlope\.com$ instead of the (.*) bit... which means it'll match only for an optional www. and won't match/rewrite the ai. or other subdomain rules. For millenium I just had to change the last line from "^/" to "^$" meaning an empty string, rather than a slash. Other those those, I just reordered things so they make a bit more logical sense. Test and make sure it all works though.
Title: Re: Subdomains using server side .htaccess files
Post by: Miluette on April 14, 2008, 11:36:40 PM
Oh neat, everything works now! Thanks for all your help *_*
One thing though. Now things relating to jessicacantlope.com revert to the xepher address when you leave off the final slash again. Not that it'll be a big deal since it'll be two pages at most (unless somebody uses ai.jessicacantlope.com...). I'm just real super-picky about this kind of thing, lol.

<3
Title: Re: Subdomains using server side .htaccess files
Post by: Xepher on April 15, 2008, 04:04:26 PM
Oh wow... that took me WAY too long to figure out. What I didn't realize was that original bit to add the trailing slash... well it was using REQUEST_FILENAME and checking if it's a directory. That means it has to be a real (unremaped) file, and that wouldn't exist for any of your remapped subdomains, so it was going through and remapping the other stuff first, even though it was at the top of the file AND had a "L" flag on it. Eventually I figured out the code below...

RewriteCond    %{REQUEST_URI}  !(.+)\.(.+)$
RewriteCond    %{REQUEST_URI}  !(.+)/$
RewriteRule    ^(.+)$           http://%{HTTP_HOST}/$1/  [L,R]


What that's gonna do is check that there's no dot/period in the URL (as that would indicate it's a file) and that it doesn't end with a slash... THEN it'll redirect, adding the slash, and to the same hostname it got the request under. It's not perfect though, if you have regular files that don't have a "dot" in their filename (or directories that do) then it'll break. If that's a problem well... then it gets a lot more complicated again. For now, I think it's working, and the changes are already made in your .htaccess file (since that's where I did my testing.)
Title: Re: Subdomains using server side .htaccess files
Post by: Miluette on April 16, 2008, 08:56:36 PM
Oh! That's wonderful. <3
No, I don't think it'll get any more complicated than that, hee. Thanks so much.