Connecting Tech Pros Worldwide Forums | Help | Site Map

MySpace-like .htaccess config with ForceType directive

Newbie
 
Join Date: Jun 2007
Posts: 8
#1: Aug 22 '07
Hello there thanks for your attention,
I'm tryin to make somethin like myspace with htaccess. Which should be a extension-less link like http://www.mysite.com/username to show user profiles. I can assign "username" to be parsed as php by sth like:
Expand|Select|Wrap|Line Numbers
  1. <File username>
  2.      ForceType application/x-httpd-php
  3. </File>
  4.  
but i don't want to have a specific page called "username" for every user. i want one single page that can parse the URL part after the ending "/" . Can someone help me please?

Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#2: Jun 4 '09

re: MySpace-like .htaccess config with ForceType directive


This is generally done on dynamic websites. A URL such as http://site.com/username will be read as http://site.com/?user=username. This can be accomplished with rewriting the URL.

Htaccess demo:
Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2.  
  3. RewriteRule ^user/(.*)$ /?user=$1 [R]
  4.  
The above would change the URL http://site.com/user/mark to http://site.com/?user=mark. You could then use whatever language you are using to obtain this value (GET).

If you want the URL to be 'masked', change the R flag to L.

Expand|Select|Wrap|Line Numbers
  1. RewriteEngine On
  2.  
  3. RewriteRule ^user/(.*)$ /?user=$1 [L]
  4.  
Reply