I might be going about this all wrong so let me know if I am.
I am creating software that allows people to sign up and have their own sub-domain on my website.
So say my website is ben.com, they could have their own sub-domain called juice.ben.com.
When they type their sub-domain juice.ben.com in their address bar, it will load the contents in a root directory.
I have also set-up a .htaccess redirect to redirect www.ben.com to ben.com. Not sure if this matters with my question but I thought I'd mention it.
Ok, so basically what I think I need to do is put the software they they've signed up to in the root directory. So when someone goes to juice.ben.com, they will be pointed to the root directory (I beleive I can set-up wild card sub-domains with my host) and the software will then analyse their sub-domain and then display their account.
Now, if someone just types in ben.com into their browser, I want it to show the contents of the ben.com/_website/ folder but still show in the address bar that they are still in the root directory.
Hopefully I am making sense
Is this possible with htaccess? If so, what do I need to do?
.htaccess - Pointing non-www to a sub-directory
Moderator: General Moderators
Re: .htaccess - Pointing non-www to a sub-directory
You want mod_rewrite, which can be one of the most confusing Apache modules.
Basically you want to make rewrite rules that say: "For any file request at the root of the website, load up that requested file from the /_website/ folder".
Basically you want to make rewrite rules that say: "For any file request at the root of the website, load up that requested file from the /_website/ folder".
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: .htaccess - Pointing non-www to a sub-directory
I've almost got it working with mod_rewrite... if I type in http://test.com/randomfile.php it loads the /_website/index.php file...
But if I type in http://test.com/ or http://test.com/inex.php it loads the root directory...
Is these some condition I can add in that makes both of those still point to the /_website/index.php file?
Here is my current code:
But if I type in http://test.com/ or http://test.com/inex.php it loads the root directory...
Is these some condition I can add in that makes both of those still point to the /_website/index.php file?
Here is my current code:
Code: Select all
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /_website/index.php [L]Re: .htaccess - Pointing non-www to a sub-directory
http://test.com/ is treated as a directory, so your third RewriteCond fails, which causes there to be no rewrite. Not sure why inex.php isn't working though - I'm assuming it's not an actual file?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.