比如,把如下url
http://www.abc.com/my/test
http://www.abc.com/my/test/
http://www.abc.com/my/test.html
都重写到
http://www.abc.com/my.php?str=test<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule my/([a-z]{1,20}[0-9]{1,16})$ my.php?str=$1&mode=0 [NC,L]
RewriteRule my/([a-z]{1,20}[0-9]{1,16})[\/]$ my.php?str=$1&mode=1 [NC,L]
RewriteRule my/([a-z]{1,20}[0-9]{1,16})\.html$ my.php?str=$1&mode=2 [NC,L]
</IfModule>
现在实现了,但能不能简化到一句呢?表达式不是很精通。还有一个问题就是,怎样匹配汉字呢?
比如把
http://www.abc.com/my/汉字
都重写到
http://www.abc.com/my.php?str=$1&mode=cn

解决方案 »

  1.   

    RewriteRule my/([a-z]{1,20}[0-9]{1,16})$ my.php?str=$1&mode=0 [NC,L]
    RewriteRule my/([a-z]{1,20}[0-9]{1,16})[\/]$ my.php?str=$1&mode=1 [NC,L]
    RewriteRule my/([a-z]{1,20}[0-9]{1,16})\.html$ my.php?str=$1&mode=2 [NC,L]你这里分mode了阿,如果不要的话可以试试 
    RewriteRule my/([a-z]{1,20}[0-9]{1,16})(\/|\.html)?$ my.php?str=$1 [NC,L]
      

  2.   


    嘿嘿,不怕汉字麻烦,iconv()解决.
      

  3.   


    RewriteRule my/([a-z]{1,20}[0-9]{1,16})(\/|\.html)?$ my.php?str=$1 [NC,L]
    -------------------------------------
    这个不是应该这样吗?RewriteRule my/([a-z]{1,20}[0-9]{1,16})(\/|\.html)?$ my.php?str=$2 [NC,L]
      

  4.   


    哈哈,搞定!
    谢谢6楼“Siramizu”
      

  5.   

    大家再帮看一下
    http://topic.csdn.net/u/20100123/19/4bd2a006-d005-4a8f-a754-5ebc2b5cba75.html
    这个是一个URL重写的,明早一起结贴!!