duanliang8464 2013-03-06 00:39
浏览 14
已采纳

mod.rewrite多个规则相同目录

I am using the following code...

#Fix Rewrite
Options -Multiviews

# Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)?$ index.php?q=$1 [L]

to turn www.website.com/index.php?q=Keyword into www.website.com/Keyword

Which works great....however....

I also (in the same directory) have a file called spec.php which accepts a GET variable of eid.

I need to also have a rule that turns www.website.com/spec.php?eid=00000 into www.website.com/00000 or www.website.com/spec/00000 without actually moving spec.php into a subdirectory.

Any help would be GREATLY appreciated, my eyes have google burn. I found some that did something similar but when I tried to match it to my situation I got problems.

  • 写回答

1条回答 默认 最新

  • douju1997 2013-03-06 02:02
    关注

    So this line here

    RewriteRule ^(.*)?$ index.php?q=$1 [L]
    

    is matching everything, if you want to have website.com/Keyword work and website.com/spec/0000 work then you need to add another condition

    I think this will work

    RewriteRule ^/spec/(.+)$ /spec.php?eid=$1 [L]
    RewriteRule ^(.*)?$ /index.php?q=$1 [L]
    

    What is this saying?

    First part is a regular expression, second part is the URL to map it to and the last part is the flags. In this instance we put the /spec/ condition first so that it is hit first as the second condition will match everything else and then make sure the [L] flag is set as that tells mod_rewrite to stop if the current condition matches.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题