如何使用.htacess进行URL重写

时间:2015-04-26 15:03:04

标签: .htaccess url mod-rewrite url-rewriting

我需要一些帮助,使用.htaccess重写URL我的网址如下:

http://www.example.com/testro2/product.php?id=426834&productStore=396

我需要让它与文本一起使用,例如:

http://www.example.com/testro2/product/{anythinghere}/id=4268334&productStore=369

或者你可以让它看起来更清晰,例如删除id=&productStore=会很棒,否则我可以使用它们。示例

http://www.example.com/testro2/product/{anythinghere}/4268334/396

问题是我需要在URL中使用我的关键字anythinghere

另外,我想改写

http://www.example.com/testro2/search.php?q=shoes 

http://www.example.com/testro2/search/shoes

1 个答案:

答案 0 :(得分:0)

您可以将此代码放入/testro2/.htaccess

RewriteEngine On
RewriteBase /testro2/

RewriteRule ^product/.+/(\d+)/(\d+)$ product.php?id=$1&productStore=$2 [L]
RewriteRule ^search/(.+)$ search.php?q=$1 [L]
相关问题