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条)

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大