How do I make subdomains point to a subfolder with .htaccess?

How do i convert

http://something.domain.com to –> http://domain.com/something
using .htaccess
tricking the browser and person into thinking they have an actual subdomain

You can try something like this:

# if requested subdomain is not "www"
RewriteCond %{HTTP_HOST} !^(www\\.)?example\\.com [NC]
# and we have not already rewritten this request to the subdomain's subfolder
RewriteCond %{THE_REQUEST} !/folder/.
# extract requested subdomain to %2
RewriteCond %{HTTP_HOST} ^(www\\.)?([^.]+)\\.example\\.com
# rewrite the request to the subdomain's subfolder
RewriteRule (.*) /folder/%2/$1 [L]

I tried it and it doesn’t work.

I got this code though.


RewriteEngine On
Options Indexes FollowSymlinks Multiviews
RewriteBase /
RewriteCond %{HTTP_HOST} forum.hostingz.org
RewriteCond %{REQUEST_URI} !forum/
RewriteRule ^(.*)$ http://www.hostingz.org/forum/$1 [L]

What it does is that it redirects http://forum.hostingz.org to http://hostingz.org
But by redirecting the url changes, is there a way I can use masking or something like that so url doesn’t redirect?

NO! That is a security issue (making an external redirect) so it is a design feature that you WILL have the new URL displayed.

Regards,

DK

So what does wordpress MU do then? It doesn’t exactly edit the .htaccess file as it works with shared hosting.

I found a post here which helps solve the problem

http://forum.hostingz.org/ redirects to http://hostingz.org/forum
and it works so much that I can even get http://forum.hostingz.org/viewforum.php?f=2&sid=0440b9d4f8a6d67c105642a567d3e390

Do you know how I found this page in less than 5 minutes?
I used this useful .htaccess search engine and then I searched for [URL=“http://www.google.com/custom?q=subdomain+&btnG=Search&hl=en&client=pub-4356884677303281&channel=5406184974&cof=FORID%3A1%3BAH%3Aleft%3BS%3Ahttp%3A%2F%2Fwww.askapache.com%2Fcse%2F%3BCX%3AApache%2520%252Ehtaccess%2520Search%3BL%3Ahttp%3A%2F%2Fz.askapache.com%2Fcse.gif%3BLH%3A83%3BLP%3A1%3BVLC%3A%23663399%3BGALT%3A%23009900%3BGFNT%3A%23999999%3BGIMP%3A%23999999%3BDIV%3A%23336699%3B&cx=002660089121042511758%3Akk7rwc2gx0i&adkw=AELymgWepKYpZfkF7meHsAn5i20JGZsSpeeBSgNHNX1ZuMl4yc-OhLui7Bh5vVNvqZHNVMzUoyV8RfR9WYd9BpUPTIQc4eD-5e6Uqchlngtt1qT6IXxUdZIvxdiUfdu1l6LL29DscrojgJ3ZnuDQltnRnDkVqPepcarqVMEBTmwiHlU2zR5RsQWZIsIE_D7Eygy_2-2U9a2ms6fxxk6KZbMVkN_0dH8xxQ&sa=2”]subdomain.

The results are amazing!

des,

Redirection is easy to hide (the change of URI) but a redirection to a different server (a subdomain IS a different server) must be displayed to the visitor. You asked for a hidden redirection to a different domain but showed both types in your examples.

http://forum.hostingz.org/ redirects to http://hostingz.org/forum
and it works so much that I can even get http://forum.hostingz.org/viewforum…5642a567d3e390

subdomain.domain.com/whatever => domain.com/subdomain/whatever MUST be displayed

subdomain.domain.com/ => subdomain.com/whatever can be hidden

As usual, it’s all in the specification.

Regards,

DK