我有一个.htaccess文件,可以执行多个重写命令并且运行良好。然而,在测试时,我遗漏了一个关键信息,在$ _SERVER变量中设置了id(我在php脚本中使用了$ _SERVER)。用mod_rewrite设置一个服务器变量,以及重定向
我有一个URL example.com/f/847f34c76f64cad96effc8e9c3cea176其中长字符串代表一个id和f代表处理请求的脚本。
我有以下重写,它处理脚本部分。
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteCond %{REQUEST_URI} ^/f/(.*)$ [NC]
RewriteRule^/scriptf.php [L]
就像我说的,这会正确处理重定向。但是,我也需要把id放在一个环境变量中。像这样的东西是我在想的
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteCond %{REQUEST_URI} !=/robots.txt
RewriteCond %{REQUEST_URI} ^/f/(.*)$ [NC]
RewriteRule^- [E=id:$1]
RewriteRule^/scriptf.php [L]
但可惜这不起作用。
此外,在查询中发送ID不是我的案例的有效解决方案。
编辑:参考错误日志输出:
[Tue Oct 08 10:48:31 2013] [error] [client 192.168.77.53] Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
看起来你是在正确的轨道上,但你需要在你的ENV行使用'%1'而不是'$ 1',因为你从'RewriteCond'匹配它。 –
我确实将其更改为%1,但仍然收到500错误 –
查看错误日志。你会发现500错误实际上是什么。 –