|
|||||||
| PHP Discussion and technical support for using and deploying PHP based websites. |
![]() |
|
|
Thread Tools | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
Hi
I was wondering how do they do that website.com/any-username thing? Just like when you signup at twitter, you get u a vanity url like twitter.com/cancer10 Does anyone know? Pls if someone can explain ![]() Thanks
__________________
CupidSystems.com - Web Design and Web Development Services |
|
#2
|
||||
|
||||
|
Most likely via URL rewriting at the web server level, converting the user name portion to a URL query string "name=value" pair. Then it would be available to the script as $_GET['name'], which would be used (after sanitizing and escaping) to query the DB to display the user's data.
In other words, the web server would rewrite "http://www.example.com/nogdog" to "http://www.example.com/index.php?name=nogdog".
__________________
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ Terry Pratchett in Nation Kindle Minds (blog about Amazon Kindle) |
|
#3
|
||||
|
||||
|
What is the syntax for it?
Where do I write it? Thanks
__________________
CupidSystems.com - Web Design and Web Development Services |
|
#4
|
||||
|
||||
|
Depends on the web server. If you're running under Apache, it would either be in the httpd.cnf file or at the directory level in a .htaccess file. Do a search on something like "apache mod_rewrite" or "apache url rewriting" for syntax and examples. (I don't happen to have it memorized.)
__________________
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be." ~ Terry Pratchett in Nation Kindle Minds (blog about Amazon Kindle) |
|
#5
|
||||
|
||||
|
It's usually in the .htaccess file and uses regular expressions (google it).
It could look something like this: Code:
RewriteEngine On RewriteRule ^[^\/\?]*$ index.php?username=$1 |
|
#6
|
|||
|
|||
|
I have the re-writing working correctly but here's my problem...
I have thrusong.com/username. It forwards to thrusong.com/user/profile.php?id=username. The problem I'm having is that profile.php thinks its in the main folder when a vanity url is used, not /user, and since the page is being used with users who set their vanity url, and those who don't, the page doesn't work as correctly for the vanity URLs. Can I modify the conventional rewrite rule so that even when thrusong.com/username forwards to thrusong.com/user/profile.php?id=username the page still uses the links and paths correctly? |
|
#7
|
||||
|
||||
|
Why not just use links relative to DocumentRoot?
|
|
#8
|
|||
|
|||
|
PHP Code:
|
|
#9
|
|||
|
|||
|
Quote:
Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-F
RewriteRule ^([-_!*$@~:.a-zA-Z0-9]+)$ http://www.yoursite.com/profile.php?username=$1
![]() copy the code above and paste it in .htaccess file and upload it, it should do the work
|
|
#10
|
||||
|
||||
|
Question:
For multiple pages, do I have to write the code as: Code:
RewriteEngine ON RewriteRule ^.*/([^/\.]+)/?$ userPage.php?page=$1 [L] RewriteRule ^.*/([^/\.]+)/?$ questions.php?page=$1 [L] RewriteRule ^.*/([^/\.]+)/?$ comments.php?page=$1 [L]
__________________
CupidSystems.com - Web Design and Web Development Services |
|
#11
|
|||
|
|||
|
Well, I think that is depended on the server, if you are under the apache like that .The problem I'm having is that profile.php thinks its in the main folder when a vanity url is used, not /user, and since the page is being used with users who set their vanity url, and those who don't, the page doesn't work as correctly for the vanity URLs.
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|