views:

41

answers:

3

I'm trying to convert a simple url (below) in to a blog-style url, but not quite sure how to do it, all of my other rules are working fine, but I can't seem to figure this one out.

URL I want to convert: http://www.website.com/myblog.php?id=1&title=My+blog+title

URL I want it to create: http://www.website.com/1/my-blog-title

What should the rule be?

Any assistance appreciated :)

+2  A: 

Try this in your .htaccess file:

RewriteEngine on
RewriteRule ^(\d+)/([^/]+)$ myblog.php?id=$1&title=$2

But here the hyphens are not replaced by plus signs.

Gumbo
+1  A: 

Try this

RewriteEngine on
RewriteBase /
RewriteRule ([0-9]+)/([^.]+) myblog.php?id=$1&title=$2
Lizard
Hi Lizard, after further messing around and investigation, I've decided on using this one, checking the numeric value made the difference. Many thanks!
Lee
+1  A: 

in your .htaccess file,

RewriteEngine On
RewriteRule ^([^/]*)/([^/]*)$ /myblog.php?id=$1 [L]

You don't (well shouldn't) need to pass the blog title to the blog file, only the ID. Hope this works

Foxtrot
Superb thank you, this out of the three seemed to work. Not sure why the others didn't, maybe the way I explained the requirement. But thanks all!
Lee
you're very welcome. While I cannot give a definite answer without some trial and error with the bottoom two, it could very well be the lack of a / in the destination path which establishes the path to originate from the html docroot dir.one quick thing, make sure you sanitize $_GET['id'] before passing it off to a mySQL query.
Foxtrot