Create SEO-friendly URL with PHP with just the Querystring Value
Is there a way use mod_rewrite 开发者_StackOverflow中文版to produce the result below?
Original URL: http://www.domain.com/shop.php?id=newyork
to
SEO friendly URL http://www.domain.com/newyork
I've seen plenty of example where the above URL can be converted to http://www.domain.com/shop/newyork but I actually don't want to display the word 'shop/' so just http://www.domain.com/newyork
I'd have a go with something like the following, off the top of my head
RewriteRule ^([a-zA-Z]*)$ www.example.com/shop.php?id=$1
Do bear in mind that anything after your root domain, will be piped into your shop.php script.
Yes, in your .htaccess file put
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^/([^/.]+)$ shop.php?id=$1 [L]
</IfModule>
([^/.]+)
will match anything that isn't a /
or .
and store that info,
$1
at the end outputs that info into your shop script.
[L]
tells mod_rewrite to stop looking for rules if this one works.
Based on your example:
RewriteRule ^([a-z]+)$ /shop.php?id=$1 [L]
Would match newyork
, alaska
, hamburg
but not highway-1
.
精彩评论