doushao5047 2013-05-16 11:13
浏览 42
已采纳

具有多个参数的htaccess重写规则

This is my .htaccess file:

Options +FollowSymLinks
Options -Multiviews

RewriteEngine On
RewriteBase /website/

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .? - [S=20]

RewriteRule ^(.*)$ $1.php 
RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?occ=$1&cat=$2

now these 2 lines together are not working for example:

if I were to go to contact.php, I would type in my url: localhost/website/contact and it would work

however if I want to go to location/website/index.php?occ=occasion&cat=category by typing this in my url: localhost/website/occasion/category it will only work if I remove the first rewrite rule

but then I cant go to localhost/website/contact anymore

what am I missing here?

  • 写回答

2条回答 默认 最新

  • dongmaoxi0477 2013-05-16 11:20
    关注

    Your Problem is your order.

    /website/occasion/category first gets rewritten to be /website/occasion/category.php, which then fails to match the second rule.

    RewriteRule ^([a-z0-9_-]+)/([a-z0-9_-]+)(/)?$ index.php?occ=$1&cat=$2 [L]
    RewriteRule ^(.*)$ $1.php
    

    Changing the order and adding the [L] parameter to the rule (stop executing followup rules after succesful execution) should fix the issue.

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

报告相同问题?

悬赏问题

  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么