regex - htaccess 正则表达式不附加获取值
问题描述
首先,为这个相当直率的标题道歉,我有点初学者htaccess
,所以请多多包涵。我正在尝试为我网站上的图像创建一个小的防热链接脚本(您可以在此处查看格式更好的正则表达式:
Options -MultiViews
RewriteEngine On
# RewriteBase /
# only allow rewriting to paths that dont exist
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ruid\.php(?:/t(\d))?/r(\d{2,4})x(\d{2,4})?/([\w-]+)/?$ ruid.php?type=$1&width=$2&height=$3&image=$4 [L,NC,QSA]
# no php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
例如,如果我去
www.example.com/ruid.php/t1/r400x500/313ef70
它应该指向
www.example.com/ruid.php?type=1&width=400&height=500&image=313ef70
但是,当我var_dump
输入$_GET
数据时ruid.php
,我收到一个空数组:
// returns array(0){}
die(var_dump($_GET));
在搜索了一会儿之后,试图找到合适的标志和语法来htaccess
重写,我没有找到任何可以解决我的问题的方法。
感谢所有帮助。
解决方案
您可以将此规则与经过调整的正则表达式一起使用:
Options +FollowSymLinks -Indexes -MultiViews
RewriteEngine On
RewriteBase /
# only allow rewriting to paths that dont exist
RewriteRule ^ruid\.php(?:/t(\d))?/r(\d{2,4})x(\d{2,4})?/([\w-]+)/?$ ruid.php?type=$1&width=$2&height=$3&image=$4 [L,NC,QSA]
# no php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
+
最后一个参数使用量词- 使用
\w
代替[a-zA-Z0-9_]
- 无需
/
逃避mod_rewrite
规则
推荐阅读
- javascript - 如何解析来自 webRTC 流的数据?
- python - 每次迭代时for循环调用函数中的ipyleaflet on_click事件
- shortest-path - 有序点/节点组之间的最短路径,一次从每组一个点,最终循环到达所有点
- spring-jms - Spring Boot 中的 XA 事务
- asp.net-mvc - 如何在 AD B2C 中使用图形 api/sdk
- next.js - Nextjs 页面加载了两次,因此失败
- javascript - 为什么 phaser.js 显示整个 sprite-sheet 而不是它的单个帧?
- python - 以编程方式构建代理时,无法使用 webview 向浮士德代理/主题发送消息
- python - Pandas 和 Numpy 版本的问题
- telegram - 如何使用 python-telegram-bot 库从测验中识别用户答案