MilMike
MilMike

Reputation: 12831

Mod Rewrite URL with Number

I want to rewrite an url from example.php?id=123 to example-123-hello-world
(where "hello-world" is some fake text)

I tried this:

RewriteRule ^example-(.*)-(.*)$ /example.php?id=$1

it works only if there are no "-" in hello world:

example-123-helloworld 

Any ideas how to do this? thanks a lot! :)

Upvotes: 0

Views: 69

Answers (2)

Book Of Zeus
Book Of Zeus

Reputation: 49867

here's what you need to use:

RewriteEngine On
RewriteBase /
RewriteRule ^example\-([0-9]+)\-(.*)/?$ example.php?id=$1 [NC,QSA,L]

Upvotes: 4

Dmitry Teplyakov
Dmitry Teplyakov

Reputation: 2898

Try this:

RewriteRule ^example-(.*?)-(.*)$ /example.php?id=$1

Upvotes: 1

Related Questions