htaccess转换为友好的URL

时间:2014-06-03 16:46:30

标签: php .htaccess mod-rewrite

原始网址 http://localhost/store/?til=product&id_product=25&title=blue-basket

通缉网址 http://localhost/store/products/blue-basket

我想知道是否有某种方法可以隐藏id_product=25的变量,如果没有,它应该是这样的:

http://localhost/store/products-25/blue-basket

我有这个.htaccess:

Options +FollowSymLinks
RewriteEngine On

RewriteBase /store/

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)?product&id_product=(.*)\ HTTP
RewriteRule ^ /store/products=%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^products=(.*)$ ?til=product&id_product=$1 [L,QSA]

结果: http://localhost/store/products=25&title=blue-basket

1 个答案:

答案 0 :(得分:1)

尝试:

Options +FollowSymLinks -Multiviews
RewriteEngine On

RewriteBase /store/

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /store/(?:index\.php|)\?til=product&id_product=([0-9]+)&title=([^&\ ]+)
RewriteRule ^ /store/products-%1/%2? [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^products-([0-9]+)/(.*)$ ?til=product&id_product=$1&title=$2 [L,QSA]