Page 1 of 1
Easy (???) question...
Posted: Thu Mar 06, 2008 9:10 am
by Panzram
I want users to be able to access their own web-pages with URLs
http://www.mysite.com/usersite1,
http://www.mysite.com/usersite2 etc, without having folders usersite1, usersite2 etc. Is this possible? And, if so, how?
All of their content and design is stored in a database, so there's no real need for folders. It will only create problems for me as admin.
Thanks.
Re: Easy (???) question...
Posted: Thu Mar 06, 2008 9:19 am
by Sekka
This is very doable, but a bit of work is required. I refer to this technique as 'virtual' URLs. F**k if I know what the real name is though.
Anyway, in the root of your website, you need to add to the (or create a) .htaccess file the following code,
Code: Select all
RewriteEngine on
# Fix requests without last slash
RewriteCond %{REQUEST_URI} !/$
RewriteCond %{REQUEST_URI} !\.
RewriteRule (.*) /$1/ [R=301,L]
# 'Virtual' URL
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L,QSA]
What does this do? Any request that is not a file, e.g. /folder/file.jpg, or existing folder, will be forwarded
internally to index.php in the root.
When I said internally, it means just that. The user will still see /my/request/ in their address bar, but the server is now working on /index.php.
You need to then figure out what URL the user was trying to access. You can do this using a server variable. $_SERVER['REQUEST_URI'] gives the URL the user requested (aka what is in their address bar). You can use this to determine what URL they wanted, and as such, display the relevant page.
All that make sense?
Re: Easy (???) question...
Posted: Thu Mar 06, 2008 9:23 am
by Panzram
Excellent answer and so to the point! Thanks a bunch.
Re: Easy (???) question...
Posted: Thu Mar 06, 2008 12:09 pm
by kryles
I'm sure you'll get this from a Moderator eventually, but you have to make your titles a little more specific to the problem.
Re: Easy (???) question...
Posted: Fri Mar 07, 2008 2:45 am
by Panzram
I am aware of it, but it was hard to make my question into specific one-liner. How would you have formulated the title?
Re: Easy (???) question...
Posted: Fri Mar 07, 2008 10:26 am
by kryles
how to enable users to view http://...uni1 and
http://uni2 without having folders for them
Horrible description, but yah lol.