How to make www.mysite.com/ + personal extension name?
Hello everybody, I have a PHP personal space systems. It allows user registration, then get a personal space. But all it points the URL address to www.mysite.com. What php documents should I modify, make it like FACEBOOK: each user has his own URL address, convenient to share with his friends. (www.mysite.com/ + personal extension name) Thanks.
3 Answers
Thank you for a detailed explanation.
And this is a good anwser. Posted: youlichika 0 of 0 people found this answer helpful. Did you? Yes No
I recommend you to use a path prefix like /user/… to avoid conflicts with other existing URLs like e.g. /register.
Posted: Go 2 of 2 people found this answer helpful. Did you? Yes No
ok with your PHP its can be easy, just use the .htaccess RewriteRule tricks.
Your web server needs to know how to handle such URLs. Most web server software has an extension that allows to rewrite requested URLs internally. As for Apache’s web server there is mod_rewrite that allows a rule based URL rewriting. In you case you could use the following rule in the .htaccess file to rewrite such requested URL paths internally to a user.php file: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^[^/]+$ user.php [L]Note that this rule does only add a new way to request /user.php; so it is still possible the request /user.php directly. Within the user.php you can access the requested URI path with $_SERVER[\'REQUEST_URI\']. To extract the user name, you could use the following: $_SERVER[\'REQUEST_URI_PATH\'] = parse_url($_SERVER[\'REQUEST_URI\'], PHP_URL_PATH); $username = substr($_SERVER[\'REQUEST_URI_PATH\'], 1);Now you just need to adjust your application to serve the proper URLs as mod_rewrite can only rewrite incoming requests and not outgoing responses. But apart from that, I would rather suggest a different URI design with a distinct prefix like /user/…. Otherwise users might choose URLs that conflict with existing ones like /index.html, /robots.txt, /sitemap.xml, etc. resources Posted: MacOS 3 of 3 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved