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.
Easy (???) question...
Moderator: General Moderators
- Sekka
- Forum Commoner
- Posts: 91
- Joined: Mon Feb 18, 2008 10:25 am
- Location: Huddersfield, West Yorkshire, UK
Re: Easy (???) question...
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,
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?
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]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...
Excellent answer and so to the point! Thanks a bunch.
Re: Easy (???) question...
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...
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...
how to enable users to view http://...uni1 and http://uni2 without having folders for them
Horrible description, but yah lol.
Horrible description, but yah lol.