我正在使用 mod_rewrite 来重写这样的 URL:
http://example.com/1,2,3,4/foo/
Run Code Online (Sandbox Code Playgroud)
通过在 .htaccess 中执行此操作:
RewriteEngine On
RewriteRule ^([\d,]+)/foo/$ /foo.php?id=$1 [L,QSA]
Run Code Online (Sandbox Code Playgroud)
它工作正常,除了当“1,2,3,4”变成长度超过 255 个字符的字符串时,Apache 返回“403 Forbidden”。
foo.php?id=1,2,3,4直接访问没有问题,即使 id 字符串很长,但这对我来说不是一个选择。
我应该调整一些 Apache 或其他设置吗?
更新:我用 RewriteLogLevel 9 打开了 RewriteLog。使用一个短的 id 字符串,我在我的日志文件中得到了几行。但是当 id 字符串大于 255 个字符时,不会记录任何内容(好像 mod_rewrite 甚至没有执行?)。
如果您觉得这个问题有趣/有帮助,请点赞。
我们在传递查询字符串时遇到了 Apache mod_rewrite 行为的一个奇怪问题(也许是一个错误?)。
为了重现,我们使用默认的 Apache 配置设置了一个干净的 Ubuntu (oneiric) 安装。我们启用了 mod_rewrite,并且在默认站点配置中,我们添加了以下内容:
RewriteEngine on
RewriteRule ^/(.*)$ /r/$1 [R]
Run Code Online (Sandbox Code Playgroud)
为了测试,我们使用 curl:
curl -I 'http://[ubuntu-machine]/a/b%20c?a%20b'
Run Code Online (Sandbox Code Playgroud)
相关输出是:
HTTP/1.1 302 Found
Server: Apache/2.2.20 (Ubuntu)
Location: http://[ubuntu-machine]/r/a/b%20c?a%2520b
Run Code Online (Sandbox Code Playgroud)
如您所见,查询字符串被双重转义,这是错误的。有谁知道我们如何解决这个问题?我们尝试了几件事:
/的a和b部分之间被转义。手动取消转义查询字符串。
RewriteCond %{QUERY_STRING} .*
RewriteMap unescape int:unescape
RewriteRule ^(.*)$ $1?${unescape:%{QUERY_STRING}}
Run Code Online (Sandbox Code Playgroud)
然而,这意味着我们无法区分查询字符串中的an&和 an 转义&符。
更新:
此错误报告描述了相同的问题。第一条评论链接到一个明显解决问题的提交,但正如 Pieter 在下面所说的,它似乎并没有真正修复。
我喜欢这个简单的重写规则:
/somefolder/mypage.aspx?myid=4343&tab=overview
Run Code Online (Sandbox Code Playgroud)
重定向到:
/folder/4343/overview/
Run Code Online (Sandbox Code Playgroud)
我寻找了一些解决方案,但没有一个真正奏效。
我试过:
rewrite ^/somefolder/mypage.aspx?myid=(.*)&tab=overview$ /folder/$1/overview permanent;
Run Code Online (Sandbox Code Playgroud)
和
rewrite ^/somefolder/mypage\.aspx\?myid=(.*)&tab=overview$ /folder/$1/overview permanent;
Run Code Online (Sandbox Code Playgroud)
我究竟做错了什么?我收到 404
(更简单的规则工作得很好..)
谢谢
是否可以使用URL 重写来提供比它具有的“附加查询字符串”复选框更复杂的查询字符串功能?具体来说,是否可以为某些查询字符串参数指定键并让它只附加那些名称值对。
例如,对于输入:
http://www.example.org/test?alpha=1&beta=2&gamma=3
以及查询字符串参数键列表:beta gamma
它应该输出:http : //www.example.org/redirect?beta=2&gamma=3
(请注意,输入中的查询字符串参数以任意顺序出现。)
我知道我的设置有点疯狂,但无论如何......
我在 Openshift 上设置了 Nginx 来缓存地图图块(对于地图查看器,您可以猜到目的,:-)),这些图块由我的家庭网络提供,该网络带宽有限(愚蠢的无线连接!)。Openshift 为我提供了无限带宽和 1 GB 磁盘,这应该足以缓存地图的热门部分。
但是,地图查看器喜欢发出这样的请求:
http://localhost/tiles/world/t/-1_0/-27_23.png?1381358434308
Run Code Online (Sandbox Code Playgroud)
这让 nginx 认为该文件不可缓存!我已经做了一些谷歌搜索,但由于我在阅读和编写正则表达式方面很糟糕,我想(从你那里)请求一种方法让 nginx 忽略 .png 文件的查询字符串,并且只从缓存中提供版本而不需要请求参数。
以下是服务器配置的相关部分:
http {
proxy_cache_path ${OPENSHIFT_RUNTIME_DIR}/cachefile levels=1:2 keys_zone=my-cache:599m max_size=700m inactive=250m;
proxy_temp_path ${OPENSHIFT_RUNTIME_DIR}/cachefile/tmp;
include mime.types;
default_type application/octet-stream;
# Format for our log files
log_format main '$remote_addr - $remote_user [$time_local] $status '
'"$request" $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
sendfile on;
keepalive_timeout 5;
access_log ${OPENSHIFT_LOG_DIR}/access.log;
port_in_redirect off;
server_tokens off;
tcp_nopush on; # off may be better for Comet/long-poll stuff
tcp_nodelay off; # on may be …Run Code Online (Sandbox Code Playgroud) 这个 htaccess 片段应该重定向
myhost.com/?p=1&preview=true
到
alt.myhost.com/?p=1&preview=true
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^myhost.com$ [NC]
RewriteRule ^/\?p=([0-9]+)&preview=true$ http://alt.myhost.com/?p=$1&preview=true [NC,R=301,L]
Run Code Online (Sandbox Code Playgroud)
但出于某种原因,我无法逃脱 / 和 ? 网址的一部分。不知道为什么这不起作用......
我试过逃跑吗?
\\? \? [?]
Run Code Online (Sandbox Code Playgroud)
我试过逃避 /
\\/ \/ [/]
Run Code Online (Sandbox Code Playgroud)
这些似乎都不起作用......
帮助!
比较这两个RedirectMatch。第一个不起作用:
RedirectMatch 302 ^/redirect\.php[?]page=(.+)$ http://somewhereelse.com/$1
Run Code Online (Sandbox Code Playgroud)
与此相反,它将重定向到http://somewhereelse.com/?page=wherever:
RedirectMatch 302 ^/redirect\.php([?]page=.+)?$ http://somewhereelse.com/$1
Run Code Online (Sandbox Code Playgroud)
是否RedirectMatch只匹配 URI 而不是查询字符串?Apache 的文档在这方面有点含糊。我想要做的是提取page查询参数并使用它重定向到另一个站点。
这是可能的RedirectMatch还是我必须使用RewriteCond+ RewriteRule?
有没有办法解析wireshark中的HTTP请求数据?例如,我可以在 HTTP GET 请求(由我的机器发送)时公开请求参数,以便我不需要阅读(有时)截断的 URL 并自己找到它们?
我在 Firefox 上使用 Tamper Data 和 Firebug 来分析这些请求,但它们不如用于监视我的网络接口的独立工具可靠,但wireshark 保留了关于 HTTP 流的原始数据。
如果你们知道任何其他独立工具可以做到这一点(必须与 Linux 兼容),请告诉我。
谢谢!
我们有以下 url 我们想要代理缓存:
file.php?parameter=one¶mater2=two&r=EPOCHTIMESTAMP
Run Code Online (Sandbox Code Playgroud)
查询字符串参数“参数”因请求而异。“paramater2”也是如此。
查询字符串参数 r 是我们用来确保客户端不提供缓存(在客户端)内容的时间戳。又名“缓存破坏者”。是的,我们还使用了所有适当的不缓存 h 标头。
现在,我们想通过 nginx 代理缓存其中的一些请求。是否可以指示 nginx 忽略 r 查询字符串参数,但在为条目设置缓存键时使用所有其他参数?如果我们不能忽略参数 r,那么 nginx 代理缓存将毫无用处,因为每个缓存键都是唯一的。
谢谢。
我目前正在使用 Vagrant 为本地开发设置一台机器。一切都按预期运行,期望查询参数不会在子页面上传递给 PHP。
这意味着 on www.example.com/?a=b,查询参数是可访问的,但www.example.com/subpage/?a=b它不是。
我发现使用 Google 解决此问题的一般答复是修改try_files指令,但这对我不起作用。我还检查了request_order与variables_order中php.ini-一切都设置正确那里。
这是我的配置:
server {
listen 80;
server_name example.com www.example.com;
root /var/www/public;
location / {
index index.html index.htm index.php;
try_files $uri $uri/ /index.php?$query_string;
include /etc/nginx/fastcgi_params;
}
location ~ \.php$ {
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $request_filename;
include /etc/nginx/fastcgi_params;
}
sendfile off;
}
Run Code Online (Sandbox Code Playgroud)
因为我对服务器设置和管理不太了解,所以我在这里碰壁了,但我还检查了一些事情:
$query_string设置/etc/nginx/fastcgi_params为fastcgi_param QUERY_STRING $query_string;对我来说似乎正确。fastcgi_params是正确的由于它不在子页面上时工作,我现在怀疑位置块不匹配,但我真的不明白这是怎么回事 - 请帮忙。
我有这个网址:
mysite.com?var=var&var2=var2&var3=var3
Run Code Online (Sandbox Code Playgroud)
我想阻止这个特定的 url,但不会以任何方式影响同一基本 url 上的其他查询字符串。
是否有可能做到这一点?
谢谢,