Question

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

Was it helpful?

Solution

Try this

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

OTHER TIPS

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.

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top