Reputation: 31
I've been looking for an answer but I just can't find one. I'm not looking for a way for a user on my site to be able to quickly get to their page, and quite frankly, the same question keeps popping up, "How to Create a Facebook Profile URL" or, "How to use ".htaccess". I'm just looking for a simple bit of PHP that can create basic vanity URL's so I can quickly access different pages on my site and make it look more neat.
Upvotes: 1
Views: 302
Reputation: 9924
PHP doesn't support vanity URLs at all, you need to configure your webserver to use them.
.htdocs are configuration files for apache, however, your case may be:
Upvotes: 0
Reputation: 6927
Put this in .htaccess to send all requests to index.php (this is called a front controller)
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
Then put this in your index.php
<?php
// get the request
$request = $_SERVER['REQUEST_URI'];
// split the path by '/'
$params = split("/", $request);
You now can request a page like: http://foo.com/one/two/three
Your $params
variable will now look like:
$params = array('', 'one', 'two', 'three');
You can now use those parameters to call functions or redirect to pages or whatever you want.
This is a very simplified example but it should give you the basic idea.
Upvotes: 2