www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Server-Side Development > PHP

    PHP Discussion and technical support for using and deploying PHP based websites.

    Reply
     
    Thread Tools Rate Thread Display Modes
      #1  
    Old 08-26-2009, 11:24 PM
    cancer10's Avatar
    cancer10 cancer10 is offline
    The Himalayan Warrior
     
    Join Date: Sep 2006
    Location: India
    Posts: 430
    Question website.com/username

    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
    Reply With Quote
      #2  
    Old 08-26-2009, 11:41 PM
    NogDog's Avatar
    NogDog NogDog is online now
    High Energy Magic Dept.
     
    Join Date: Aug 2004
    Location: Ankh-Morpork
    Posts: 14,726
    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)
    Reply With Quote
      #3  
    Old 08-26-2009, 11:48 PM
    cancer10's Avatar
    cancer10 cancer10 is offline
    The Himalayan Warrior
     
    Join Date: Sep 2006
    Location: India
    Posts: 430
    Question

    What is the syntax for it?

    Where do I write it?



    Thanks
    __________________
    CupidSystems.com - Web Design and Web Development Services
    Reply With Quote
      #4  
    Old 08-27-2009, 03:32 AM
    NogDog's Avatar
    NogDog NogDog is online now
    High Energy Magic Dept.
     
    Join Date: Aug 2004
    Location: Ankh-Morpork
    Posts: 14,726
    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)
    Reply With Quote
      #5  
    Old 08-27-2009, 04:10 AM
    Teufel's Avatar
    Teufel Teufel is offline
    Occasional Geek
     
    Join Date: Apr 2008
    Posts: 157
    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
    Reply With Quote
      #6  
    Old 11-09-2009, 11:02 AM
    ckts ckts is offline
    Registered User
     
    Join Date: May 2008
    Posts: 46
    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?
    Reply With Quote
      #7  
    Old 11-09-2009, 03:40 PM
    Mindzai's Avatar
    Mindzai Mindzai is offline
    Registered User
     
    Join Date: Nov 2008
    Posts: 2,462
    Why not just use links relative to DocumentRoot?
    Reply With Quote
      #8  
    Old 11-19-2009, 06:06 PM
    Atal123 Atal123 is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 2
    PHP Code:
    RewriteEngine on
    RewriteCond
    %{REQUEST_FILENAME} !-F
    RewriteRule
    ^([-_!*$@~:.a-zA-Z0-9]+)$ http://www.yoursite.com/profile.php?username=$1
    place this code in the .htaccess file and upload it, it should work
    Reply With Quote
      #9  
    Old 11-19-2009, 06:10 PM
    Atal123 Atal123 is offline
    Registered User
     
    Join Date: Nov 2009
    Posts: 2
    Quote:
    Originally Posted by ckts View Post
    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?
    Code:
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-F
    RewriteRule ^([-_!*$@~:.a-zA-Z0-9]+)$ http://www.yoursite.com/profile.php?username=$1
    Dear CKTS, i saw your question and knew the answer to it, there for registered at this great website and wanted to share my knowledge with you on this topic

    copy the code above and paste it in .htaccess file and upload it, it should do the work
    Reply With Quote
      #10  
    Old 02-10-2010, 02:01 AM
    cancer10's Avatar
    cancer10 cancer10 is offline
    The Himalayan Warrior
     
    Join Date: Sep 2006
    Location: India
    Posts: 430
    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
    Reply With Quote
      #11  
    Old 02-10-2010, 09:50 AM
    davidjoshua11 davidjoshua11 is offline
    Registered User
     
    Join Date: Feb 2010
    Posts: 1
    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.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 01:08 PM.



    Acceptable Use Policy

    Internet.com
    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.