dozr162106
2014-12-01 19:33
浏览 21
已采纳

将两个$ _GET变量拆分为路径

I'm trying to write a rewrite rule that works something like:

www.sitename.com/products.php?p=product&c=category 

should become

www.sitename.com/product/category

I have tried the following, but my RegEx knowledge is far from ideal and the following does not work

RewriteRule ^(.*)/(.*)$ products.php?p=$1&c=$2 [QSA,L]

Any help is greatly appreciated!

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

3条回答 默认 最新

  • dongpu2727 2014-12-01 20:32
    最佳回答

    You can use this code in your DOCUMENT_ROOT/.htaccess file:

    RewriteEngine On
    RewriteBase /
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\w-]+)/([\w-]+)/?$ products.php?p=$1&c=$2 [QSA,L]
    
    RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
    RewriteRule ^(.+?)\.html$ $1.php [NC,L]
    
    评论
    解决 无用
    打赏 举报
查看更多回答(2条)

相关推荐 更多相似问题