Pregunta

I need to turn a query string like this:

http://localhost/view.php?id=12345

Into this:

http://localhost/12345

But, I also plan on having a string on the end of the URL for search engines to benifit from, like so:

http://localhost/12345/NameOfTheSkin

Kind of like how Wowhead do their URL's:

http://www.wowhead.com/item=49623/shadowmourne

Notice how you can change the string "shadowmourne" into anything and it'll still point to the item id 49623.

Basically, I need the string on the end to be ignored.

Any help is appreciated, cheers. :)

¿Fue útil?

Solución

RewriteRule ^/(\d+)/?.*$ /view.php?id=$1 [L]

This will rewrite http://host/1234/some-text and http://host/1234 into http://host/view.php?id=1234.

Detailed explanation:

^   -- matches at the start of the string
(   -- start match group
\d+ -- match one or more digits
)   -- end match group
/?  -- match 0 or 1 slash
.*  -- match any character 0 or more times
$   -- matches at the end of the string

Visit regular-expressions.info for complete guide of regexp.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top