dpq755012465 2013-01-17 17:58
浏览 33
已采纳

2种不同的.htaccess规则

I am trying to set up for my website two different .htaccess rules, but I still cannot find the correct solution.

I would like to route everything on website.com/almost-everything - this is working me well. And further, I would like to add yet this route: website.com/car/car_id - and here comes troubles, I don't know how to set up it.

Here are my attempts:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?skill=$1 [L,QSA]
RewriteRule ^car/(.*)$ ./index.php?id=car&car_id=$1 # the wrong rule - the page with website.com/car/car_id just doesn't display the correct file

Could you help me please with the second rule?

  • 写回答

3条回答 默认 最新

  • duanbu1998 2013-01-17 18:43
    关注

    Instead of

        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteRule ^(.*)$ index.php?skill=$1 [L,QSA]
        RewriteRule ^car/(.*)$ ./index.php?id=car&car_id=$1 # the wrong rule - the page with website.com/car/car_id just doesn't display the correct file
    

    I would do this

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+) - [PT,L]   ## passthru + last rule because the file or directory exists. And stop all other rewrites. This will also help your css and images work properly.
    
    RewriteRule ^car/(.*)$  /index\.php?id=car&car_id=$1 [L,QSA]
    
    RewriteRule ^(.*)$  /index\.php?skill=$1 [L,QSA]
    

    P.s. I seperated my rules with blank lines so it is clear how many there are. The above shows 3 distinct rules.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 表达式必须是可修改的左值
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写
  • ¥20 Qcustomplot缩小曲线形状问题