开发者

htaccess mod_rewrite:- products.php?cat=1 to /myfolder1/myproduct1/

I've got 开发者_高级运维a url type:- http://www.example.com/products.php?cat=1 which I am able to rewrite to:- http://www.example.com/myproduct1 using the following .htaccess rule:- RewriteRule ^myproduct1$ products.php?cat=1.

What rule would I need to enter if I wanted to rewrite to:- http://www.example.com/myfolder1/myproduct1/?


For any arbitrary path segments a and b in /a/b/, you can use this:

RewriteRule ^([^/]+)/([^/]+)/$ products.php?segment1=$1&segment2=$2

Edit    In response to your comment: Just put good/boy in your pattern:

RewriteRule ^good/boy$ products.php?cat=1


First thing, I assume you want something like http://www.example.com/myproduct2 redirect to http://www.example.com/products.php?cat=2. In this case youd' rather use that rule:

RewriteRule ^myproduct([0-9])$ products.php?cat=$1

Then you can do th same this for your folder, writing something like:

RewriteRule ^myfolder([0-9])/myproduct([0-9])$ products.php?folder=$1&cat=$2

Edit

Then you just have to write:

RewriteRule ^folder1/myproduct1$ products.php?cat=1
RewriteRule ^myfolder/differentproduct$ products.php?cat=2

and so on...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜