douyinyi7766
2014-10-02 15:07
浏览 66
已采纳

用.htaccess重写get参数?

i want a htaccess url like

mysite.com/category/1

for

mysite.com/category.php?cat=1

my htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

Have an simple idea ? Thank you :-)

图片转代码服务由CSDN问答提供 功能建议

我想要一个htaccess网址,如

  mysite.com/ 类别/ 1 
   
 
 

 <代码> mysite.com/category.php?cat=1
   
 
 

my htaccess

  RewriteEngine On 
RewriteCond%{REQUEST_FILENAME}!-f 
RewriteRule ^  ([^ \。] +)$ $ 1.php [NC,L] 
   
 
 

有一个简单的想法吗? 谢谢你: - ) \ n

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

1条回答 默认 最新

  • dormbaf90464 2014-10-02 15:17
    最佳回答

    You are not capturing the right information (you should split the name from the number) and you are not adding the query variable:

    RewriteRule ^([^\.]+)$ $1.php [NC,L]
    

    should be something like:

    RewriteRule ^(\w+)/(\d+)$ $1.php?cat=$2 [NC,L]
                       ^^^^^ capture the number
                 ^^^^^ capture the name
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题