相关疑难解决方法(0)

在Apache RewriteRule指令中设置环境变量时,是什么导致变量名称以"REDIRECT_"作为前缀?

我试图[E=VAR:VAL]在.htaccess文件中使用RewriteRule规则上的标志设置Apache环境变量(用于PHP).

我已经发现变量在PHP中作为服务器变量访问$_SERVER而不是$_ENV(这有一定意义).但是,我的问题是一些规则[E=VAR:VAL]标志按预期工作,我最终得到一个变量,$_SERVER['VAR']但对于其他规则,我以变量$_SERVER['REDIRECT_VAR']$_SERVER['REDIRECT_REDIRECT_VAR']等结束

A.什么原因导致Apache中设置的环境变量使用[E=VAR:VAL]标志通过将"REDIRECT_"添加到变量名前面来重命名?

B.我可以做些什么来确保我最终得到一个名称不变的环境变量,这样我就可以在PHP中访问它,$_SERVER['VAR']而无需检查变量名称的变体,其中有一个或多个"REDIRECT_"实例被预先添加对吗?

找到了部分解决方案.如果需要,在重写规则的开头添加以下内容将重新创建每个重定向上的原始ENV:VAR(以及在那里保留REDIRECT_VAR版本):

RewriteCond %{ENV:REDIRECT_VAR} !^$
RewriteRule .* - [E=VAR:%{ENV:REDIRECT_VAR}]
Run Code Online (Sandbox Code Playgroud)

php apache mod-rewrite naming environment-variables

70
推荐指数
2
解决办法
3万
查看次数

RewriteRule Last [L]标志不起作用?

php_flag display_errors 1
php_value auto_prepend_file init.php
RewriteEngine on 
RewriteRule ^$  /id/authenticate [R]
RewriteRule ^login_openid$  /id/login_openid.php [QSA,L]
RewriteRule ^authenticate$  /id/authenticate.php [QSA,L]
RewriteRule ^facebook$  /id/facebook.php [QSA,L]
RewriteRule ^createfromopenid$  /id/createfromopenid.php [QSA,L]

RewriteRule .* - [L,R=403]
Run Code Online (Sandbox Code Playgroud)

这是我的.htaccess文件.在我刚刚拥有的serverconfig中AllowOVerride all.

如果我请求URL,http://mydomain.com/id/authenticate我会收到403错误.如果我删除最后一条规则,它就可以了.[L]公寓不应该阻止任何进一步的规则发生吗?

编辑:

我的htaccess文件位于子文件夹"id"中,因此规则有效.

apache mod-rewrite http url-rewriting

27
推荐指数
2
解决办法
4万
查看次数

请求超出了10个内部重定向的限制

我的网站在最近几天放慢了速度.我查看了我的错误日志,发现了很多这些:

[Mon Sep 30 00:09:53 2013] [error] [client 66.249.66.205] 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.
[Mon Sep 30 00:09:53 2013] [debug] core.c(3120): [client 66.249.66.205] r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 00:09:53 2013] [debug] core.c(3126): [client 66.249.66.205] redirected from r->uri = /home/mysitecom/domains/mysite.com/public_html/index.php
[Mon Sep 30 …
Run Code Online (Sandbox Code Playgroud)

php apache error-handling .htaccess codeigniter

16
推荐指数
2
解决办法
7万
查看次数

htaccess重写XML站点地图和用户友好的站点地图

我有两个脚本:

  • xmlsitemap.php(Google XML站点地图)
  • sitemap.php(GUI用户友好的站点地图)

我想用重写规则来实现这个目标:

重写到site.com/sitemap.php
site.com/sitemap
site.com/sitemap/

重写到site.com/xmlsitemap.php
site.com/sitemap.xml

这是我尝试过的.问题是它将sitemap.xml重写为sitemap.php(GUI).

Options +FollowSymlinks
RewriteEngine On

RewriteRule sitemap.xml xmlsitemap.php
RewriteRule sitemap sitemap.php

# also tried using [L] option on both
Run Code Online (Sandbox Code Playgroud)

php apache .htaccess mod-rewrite

5
推荐指数
1
解决办法
1万
查看次数

.htaccess 停止内部重定向

首先这是我的目录结构

/localhost/p/
  .htaccess
/localhost/p/inc/
  style.css
Run Code Online (Sandbox Code Playgroud)

我有这个片段/localhost/p/.htaccess

Options -MultiViews +FollowSymLinks 
RewriteEngine On
RewriteBase /p/

RewriteCond %{REQUEST_FILENAME} ^(.+)/([^/]+)$
RewriteCond %1/inc/%2 -f
RewriteRule ([^/]+)$ inc/$1 [L]

RewriteRule ^(.+)$ index.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)

它不允许我访问文件,localhost/p/style.css但它可以让我访问index.php

这是日志

[perdir D:/p/] strip per-dir prefix: D:/p/style.css -> style.css
[perdir D:/p/] applying pattern '([^/]+)$' to uri 'style.css'
[perdir D:/p/] RewriteCond: input='D:/p/style.css' pattern='^(.+)/([^/]+)$' => matched
[perdir D:/p/] RewriteCond: input='D:/p/inc/style.css' pattern='-f' => matched
[perdir D:/p/] rewrite 'style.css' -> 'inc/style.css'
[perdir D:/p/] add per-dir prefix: inc/style.css -> D:/p/inc/style.css

// I don't know …
Run Code Online (Sandbox Code Playgroud)

.htaccess mod-rewrite redirect

2
推荐指数
1
解决办法
2895
查看次数