- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在通过教程学习创建 REST API。在本教程中,有一个步骤执行 URL 重写。代码如下:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ %{ENV:BASE}index.php [QSA,L]
谁能解释一下重写条件和其中的 %{ENV:BASE}
部分?
最佳答案
条件很简单:
如果请求的 URI 未指示任何现有文件,则重定向到 ${ENV:BASE}index.php
.
您可以找到 RewriteRule 标志的描述 here .简而言之:
QSA
代表“查询字符串追加”。这意味着查询字符串将附加到替换 URI。
L
表示这是最后一条规则,不会处理其他规则。
关于 this page htaccess 中对环境变量有很好的解释:
The %{ENV:variable} form of TestString in the RewriteCond allows mod_rewrite's rewrite engine to make decisions conditional on environment variables. Note that the variables accessible in mod_rewrite without the ENV: prefix are not actually environment variables. Rather, they are variables special to mod_rewrite which cannot be accessed from other modules.
因此,您可以像这样在规则中使用环境变量 ${ENV:<name>}
.当然,变量必须提前设置。
关于.htaccess - htaccess重写条件中的URL重写及变量解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23173706/
是否可以在 .htaccess 中包含来自另一个 htaccess 文件的规则? .htaccess RewriteEngine On RewriteCond ... RewriteRule ...
我正在尝试做的事情: 在我的特定项目的服务器上,我想通过 htaccess 编写 URL 重写规则(从 URL 中删除 .php 或 .html 扩展名)。 我的网站网址: http://enacte
在我的 .htaccess 文件中我已经有一些重写条件和规则,并且它工作正常。 现在我需要将“http 到 https 重定向”添加到我的 htaccess 文件中。 这是我的旧 .htaccess
注意:我写了解决方案。不管怎样,谢谢你。 :) 我知道这似乎是重复的问题:我搜索了很多,我应用了数十条重写规则,但它们不起作用。 我需要从 重定向 www.domain.com/folder1 到 w
我有一个带有 drupal 的多站点,我创建了一个站点,该站点起初应该可以通过多种方式(子域和路径)访问,但现在我只想保留其中一个;所以我应该重定向所有其他人。现在我有: aaa.domain.com
关闭。这个问题是off-topic .它目前不接受答案。 想改善这个问题吗? Update the question所以它是 on-topic对于堆栈溢出。 8年前关闭。 Improve this q
我将我的网站从/v1/etc... 目录移动到/v2/etc... 目录,并希望在 htaccess 中进行永久重定向。有人能帮我吗? 最佳答案 您可以使用 mod_rewrite : Rewrite
我想通过 .htaccess 保护文件夹。以下不起作用。它在浏览器中显示登录对话框,但看起来好像用户名和密码不匹配。当我将方法更改为 Basic 时,它运行良好。 AuthUserFile /home
任何人都可以解释以下行吗? RewriteRule ^(.*)$ /index.php/$1 [L] 最佳答案 重写规则的部分分解如下: 重写规则 表示此行将是重写规则,而不是重写条件或其他重写引擎指
我正在尝试从一个域中一个目录中的所有文件创建一个永久的 htaccess 重定向(301)到另一个域,如下所示: 重定向以下目录中的所有文件: http://www.primary.com/apple
我不是 .htaccess 的英雄,但我遇到了一个我认为可能是由它引起的问题。 第一个症状:对我的数据库的简单更改(如用户 IP 跟踪)每次请求都完成了多次,而站点的输出看起来还不错。 经过数小时的跟
我想做一个类似basecamp.com的东西:你公司的名字变成三级域名,http://mycompany.basecamp.com例如。我知道它(很可能)是在.htaccess文件和mod_rewri
我已阅读 this这对我的要求来说似乎太长了。 并尝试过 Redirect /index.php /index2.php但它不起作用(内部服务器错误) 我想要的是将我的一些 php 文件重定向到 in
如果使用此代码,则成功: Redirect 301 /products.php http://website.com.au/product_123.php 但是,如果执行此操作,则不是: Redire
我想重定向这个子域: http://abc.domain-name.com 到根域上使用相同名称的文件夹: http://www.domain-name.com/abc 这样,如果我尝试访问以下文件:
我已经在我的实时站点上设置了 htpasswd 身份验证,并且效果很好,但是当我在开发环境中工作时,我不想被要求输入密码。 在我的 httpd.conf 文件中,我有: SetEnv APP_ENV
之前 我安装了 SSL,一切运行良好!!这是我的根网络服务器 .htaccess 文件中的代码: Options +MultiViews RewriteEngine On RewriteCond %{
我要问一个非常简单的问题。当我运行我的页面时,我不希望我的链接显示这个: http://localhost/example/assets/gallery.php 我想要的是: http://local
我在 htaccess 中有说明,可以让所有请求都通过 index.php 文件。但它禁止访问文件夹和文件。因此,如果我尝试转到/uploads/products/thumbs/file.png 它会
我有一个这样的网址:https://example.com/coins/1&order_by=today以及几个类别,例如: https://example.com/coins/1&order_by=
我是一名优秀的程序员,十分优秀!