What's the best method for clean URLs?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

What's the best method for clean URLs?

Post by WithHisStripes »

Heya,
So I'm trying to convert:

http://www.mywebsite.com/?title=page-title-goes-here

- to -

http://www.mywebsite.com/page-title-goes-here

I'm looking for a dynamic way of doing this so anytime the user goes to "page-title..." it keeps the clean URL but tells my PHP that "page-title..." is ?title...

Does this make sense? Thanks!
Defiline
Forum Commoner
Posts: 59
Joined: Tue May 05, 2009 5:34 pm

Re: What's the best method for clean URLs?

Post by Defiline »

You should use Mod Rewrite.
.htaccess:

Code: Select all

 
RewriteEngine On
 
RewriteRule ^([-a-zA-Z0-9]+)$ index.php?title=$1
 
WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Re: What's the best method for clean URLs?

Post by WithHisStripes »

Okay - so I've been trying that method but I must be doing something wrong.

So I enter:

Code: Select all

 
RewriteEngine On
 
RewriteRule ^([-a-zA-Z0-9]+)$ index.php?title=$1
 
Then what URL do I go to to visiti http://www.sample.com/?title=sample ?

Thanks!
Defiline
Forum Commoner
Posts: 59
Joined: Tue May 05, 2009 5:34 pm

Re: What's the best method for clean URLs?

Post by Defiline »

WithHisStripes
Forum Contributor
Posts: 131
Joined: Tue Sep 13, 2005 7:48 pm

Re: What's the best method for clean URLs?

Post by WithHisStripes »

Whoops, my mistake.

I was uploading .htaccess somewhere other than it belonged.

Thanks!
Post Reply