donglanzhan7151 2015-12-08 11:08
浏览 62

.htaccess重写规则,正则表达式不起作用,返回404

I tried to resize an image with timthumb library.
I can use it directly via the following URL

http://localhost/study/server/resize/thumb.php?src=http://localhost/study/server/product/1/1/orig-1.jpg&w=160&h=130

and it works fine.

But when I rewrite my url like this

http://localhost/study/server/resize/160x130/r/product/1/1/orig-1.jpg

and add

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(resize) [NC]
    RewriteRule ^resize/(.*)x(.*)/r/(.*) resize/thumb.php?src=http://localhost/study/server/$3&h=$2&w=$1&c=1
</IfModule>

unfortunately this rule return 404 error

  • 写回答

1条回答 默认 最新

  • doubianxian6557 2015-12-08 12:10
    关注

    Use this RewriteRule

    RewriteRule ^study/server/resize/([0-9]+)x([0-9]+)/r/product/([0-9]+)/([0-9]+)/(.*)$ 
    /study/server/resize/thumb.php?src=/study/server/product/$3/$4/$5&w=$1&h=$2 [L]
    

    group 1 matches the width, zero or more digits
    group 2 matches the height, zero or more digits
    group 3 matches the first digit after /product/, one digit, you can modify if needed
    group 4 matches the second digit after /product/, one digit, you can modify if needed
    group 5 matches the filename

    This condition

    RewriteCond %{REQUEST_URI} !^/(resize) [NC]
    

    is not needed

    评论

报告相同问题?

悬赏问题

  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥30 BC260Y用MQTT向阿里云发布主题消息一直错误
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退