Forum Moderators: coopster

Message Too Old, No Replies

Personal URLs

         

J_RaD

4:50 pm on Jul 1, 2011 (gmt 0)



I've got a sideline request for a site that will generate a personalized URL based on a post card that is going out. www.example.com/john.smith for example then the page would just have their 1st and last on it when they landed on it.

I've been researching around and i can't really find a clear answer, some are very easy to, complex.

I'm not a programmer so i was looking for some script to install to get the job done.

JAB Creations

7:35 am on Jul 3, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you don't write code yourself you'll be completely at the mercy of other people and I've found that overwhelmingly to be a negative thing. You'll want an Apache rewrite. The following allows you to rewrite all requests to index.php and includes exceptions for directories (you must escape forward slashes) and the second line allows you to add exceptions for file types...

.htaccess
RewriteRule ^(directory_1\/|directory_2\/|images\/) - [L]
RewriteRule !\.(css|cur|html|jpg|png|rar|swf|svg|xhtml|xml|zip)$ index.php


Keep in mind whenever you mess with the .htaccess file that you should test it out locally until you're sure you've worked out the kinks and I would recommend testing it live only when your traffic is low. You may have other scripts, so use a # symbol to add comments (e.g. # Apache Rewrite).

Then it's a simple matter of using a scripting language (e.g. PHP) to determine what the requested path is and to look at the database to determine if there is a person with the name that matches that path. I would recommend dashes instead of periods or underscores from what I've read for SEO related purposes though you may want to look in to it yourself. If you're not familiar with PHP then get a copy of XAMPP for your OS and try the following PHP code out...

<div><pre>
<?php
print_r($_SERVER);
?>
</pre></div>


This is the basic way I'm able to keep exceptionally clean URL's at my site. Keep in mind a couple things. First you'll need to deliberately test for 404 pages and make sure that the HTTP code is 404 and not 200, otherwise someone might decide to try to sink your site by linking to 404 pages served as 200. Second when you do HTTP 301 redirects you need to use die(); or exit(); after the redirect header is sent as there is a bug in Gecko browsers where the redirect will fail if content is encountered even if a redirect header is found; without content (because of die(); directly after the header) the redirect will work successfully in Gecko browsers. The rest are just smaller details though you've now got the heavy stuff figured out. ;)

- John