0

Ok actually im not really sure whether the last string in a url is a file or a directory... for example facebook.com/skaloot. is skaloot a file (facebook.com/skaloot.php) or a directory? (facebook.com/skaloot/index.php) and how do i get rid of ".php" or "/"...

Thank you...

skaloot
  • 5
  • 3
  • 3
    \ → "backslash", / → "slash". Also, the term you're looking for is "pretty URLs". – deceze Apr 19 '11 at 08:31
  • It doesn't have to be either. – Ignacio Vazquez-Abrams Apr 19 '11 at 08:31
  • if facebook uses modrewrite (and i think they do) skaloot may be just a string passed to a totaly different file on their server. i.e. it also could be facebook.com/handler.php?q=skaloot or facebook.com/another.php?s=skaloot ..... the combinations here are endless and there is no way to find out – ITroubs Apr 19 '11 at 08:33
  • `/skaloot` is the path segment of the URL. In other words, neither a file nor a directory, just a string. – deceze Apr 19 '11 at 08:35
  • thanx for replying guys...ok lets just say that skaloot is a file...how do i get rid of ".php"... – skaloot Apr 19 '11 at 08:37
  • Are you parsing the URLs in PHP or are talking about serving files from your own server without the .php? – Treffynnon Apr 19 '11 at 08:38
  • @deceze owh...so i can just add/alter the url by adding **/skaloot** at the end of it? – skaloot Apr 19 '11 at 08:39
  • You have tagged your own question with `url-rewriting`. Have you researched in this direction? You'll need to employ some sort of URL rewriting, but what exactly you need to do depends on whether the target is a file or a folder or neither. It also depends on your web server. – deceze Apr 19 '11 at 08:39
  • A URL is just that, a URL. Arbitrary text. It does not have to correspond to any physical file or folder on the server. In Facebook's case, it most certainly doesn't. What do *you* want to do? – deceze Apr 19 '11 at 08:41
  • @Treffynnon i want my user to have their own "skaloot.my/name" without the ".php" or "/" at the back... – skaloot Apr 19 '11 at 08:42
  • possible duplicate of [.htaccess - Pretty User Profile URLs](http://stackoverflow.com/questions/930789/htaccess-pretty-user-profile-urls) – deceze Apr 19 '11 at 08:43

1 Answers1

5

Parsing URLs

$url = 'http://www.example.com/example.php';
$url = substr($url, 0, strrpos($url, '.'));
var_dump($url);
// output is: string(30) "http://www.example.com/example"

URL Rewriting

In your .htaccess file you can use mod_rewrite to rewrite pretty URLs to their actual destination.

For example:

RewriteEngine On
RewriteBase /
# If the URL does not already exist as a file
RewriteCond %{REQUEST_FILENAME} !-f
# or directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^example$ /example.php [QSA,L,NC]

The above will direct traffic hitting http://www.example.com/example to your example.php script.

Obviously replace example.com with your domain.

Subdomain option

Another option is to give your users a subdomain each. simon.sklaloot.com for example. I have previously answered a question pertaining to this: Create subdomains on the fly with .htaccess (PHP)

Community
  • 1
  • 1
Treffynnon
  • 21,365
  • 6
  • 65
  • 98