tags:

views:

38

answers:

3

Hello,

I'm creating a dictionary database using php and MySQL. The user can search for a name, if it's there it brings up a list of matching links (eg: http://mydictionary/name.php) and then the user can click on said link and they are transported to a webpage that get's its information from the database. If there is no entry for the name in the database then the user is invited to make their own entry. I can get this to work using a html input form and then the php file to save it into the database.

The problem I have is that when this newly entered name is searched for, the link won't be active as it leads to a non-existent page. Can I get php to create the new url for me? Or does anyone know a way around this problem?

Many thanks!

A: 

If i understand correctly you can do it with mod_rewrite so you can hide your name parameter, for example:

http://example.com/result.php?name=user-given name

maps to

http://example.com/user-given-name.php
fabrik
Oh ok, thanks a bunch!
sponge
A: 

What you need to do is create an .htaccess file and mod_rewrite.

This post will help you get started.

http://www.desiquintans.com/cleanurls

johnwards
Ok, that just about covers it, thanks a lot!
sponge
A: 

If the others are right about what you want, this should do what you need:

.htaccess file:

RewriteEngine on
RewriteRule ^([a-zA-Z0-9]+)\.php$ nameLookup.php?name=$1

This will rewrite all URLs like this myname.php, SomeName.php, name3.php to URLs like nameLookup.php?name=myname, nameLookup.php?name=SomeName amd nameLookup.php?name=name3

You will need mod_rewrite enabled on your apache server. You can test this by creating a PHP file with this inside:

<?php phpinfo(); ?>

Check to see if the mod_rewrite module is enabled.

Chief17
Ok, I think I've got that working, thanks so much!
sponge