Lee
Lee

Reputation: 95

Apache Rewrite rule confusion

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 :)

Upvotes: 3

Views: 177

Answers (3)

WhiskeyTangoFoxtrot
WhiskeyTangoFoxtrot

Reputation: 644

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

Upvotes: 1

Lizard
Lizard

Reputation: 44992

Try this

RewriteEngine on
RewriteBase /
RewriteRule ([0-9]+)/([^.]+) myblog.php?id=$1&title=$2

Upvotes: 2

Gumbo
Gumbo

Reputation: 655219

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.

Upvotes: 2

Related Questions