问题标签 [mod-rewrite]

For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.

0 投票
3 回答
243 浏览

apache - 覆盖所有域的 mod_rewrite 规则

有没有办法在盒子上请求的任何域上触发 RewriteRule?例如,我有 5 个 VirtualHost,它们应用了完全相同的 RewriteRule,目前每个 VirtualHost 指令都有规则,但我可以把它放在“全局”的某个地方,以便更容易维护吗?

0 投票
6 回答
1296 浏览

mod-rewrite - 干净的 URL 是后端还是前端

你怎么看.. 干净的 URL 是后端还是前端的“纪律”

0 投票
4 回答
1984 浏览

php - 获取对 POST 的跨站点 JSON 响应的最佳实践?

我正在使用具有多个子域的 Intranet。我可以控制每个子域,因此跨站点请求的安全性不是问题。我有带有 JSON 响应的 PHP 脚本,我想从多个子域调用而不重复。对于 GET 请求,我可以使用 AJAX 和 JSONP 执行此操作,但这不适用于 POST 请求。我看到了一些替代方案,但似乎都不是很好:

  • 以最小的响应发布到本地子域上的副本,然后使用 JSONP 从中央位置获取完整响应
  • 使用 JSON POST 和 GET 到本地子域上的副本
  • 使用 mod_rewrite 在后端使用带有中央脚本的本地 URL 和 JSON
  • 使用符号链接在后端使用带有中央脚本的本地 URL 和 JSON

我错过了一些更简单的东西吗?你会在这里做什么?

0 投票
4 回答
2206 浏览

java - How do I get tomcat 5.5 to run behind apache 2 with mod_rewrite passing through requests to mod_jk and stripping app context?

Ok, so I want to get a webapp running in tomcat (5.5) to run behind apache 2 (2.2.3 to be precise) serving from the root of the site (i.e. without the context), with static content being served via apache.

So if the app is running under "/myapp" on tomcat I want to use apache (plus mod_rewrite) to make it behave as if it's running under "/" instead.

Mod_jk is setup and working ok. I can access the app from "/myapp", but I can't quite get the last bit working. Below is the config I've got for mod_rewrite to try and get this working. It correctly gets rewrites /static/ urls to get apache to serve them from the unpacked webapp and if I enable the rewrite log I see that it does attempt to pass through all other requests to /myapp via mod_jk. However it seems that mod_jk is not processing the request afterwards.

When I've done this with apache 1 in the past I've had to make sure mod_jk get's loaded before mod_rewrite, but I can't seem to achieve this under apache 2. Any thoughts? How do other people usually do this?

0 投票
4 回答
11048 浏览

apache - 如何解决为什么我的重写规则没有被 apache 应用?

我有一个以 apache httpd 作为前端运行的 tomcat 6 Web 应用程序。我正在使用 mod_proxy 和 mod_proxy_ajp 将请求转发到 tomcat。我的服务器正在运行 ubuntu。现在我正在尝试使用 mod_rewrite 删除前导 www,以便我的规范网站 url 是http://domain.com而不是http://www.domain.com

我已经阅读了许多关于使用 mod_rewrite 的教程,但我无法进行任何重写。我尝试将重写规则放在 .htaccess 文件中(在修改我的 /etc/apache/sites-available/default 文件以设置 AllowOverride all 之后)。我尝试将重写规则放在 apache2.conf、httpd.conf 和 rewrite.conf 中。我已经在打开重写日志的情况下尝试了所有这些。日志文件被创建,但 apache 没有写入任何内容。我想也许 mod_proxy 以某种方式阻止了重写规则的使用,所以我也尝试禁用它......我仍然没有重写,日志也没有。

在这一点上,我完全不知道下一步该尝试什么。我该如何解决为什么 apache 没有使用我的重写规则?

作为参考,这是我的重写指令:

编辑:下面的回答对我的特殊情况有帮助,但对整个社区的帮助可能不如关于如何对 apache 指令进行故障排除的回答一般。例如,有没有办法启用日志记录,它会告诉我在请求进入时以哪个顺序应用哪些指令?

编辑2:我现在已经开始工作了。我的虚拟主机设置不正确,我也没有完全正确地重写正则表达式。这是我要工作的最终重写指令:

0 投票
1 回答
1783 浏览

mod-rewrite - 使用带有 Mod Rewrite 的通配符子域?

我有通配符子域,但是我只是不知道 mod_rewrite 到需要写这个的程度。谁能告诉我如何做到这一点,除了 www 以外的任何东西都不会进入主站点,但除此之外的任何子域都进入 /script/index.php?username=$username?

0 投票
4 回答
12486 浏览

mod-rewrite - 在匹配的 RewriteCond 上停止 Mod_Rewrite 执行

我在 IIS 上运行 Helicon ISAPI Rewrite 的免费版本,并且有多个站点通过相同的重写规则集运行。到目前为止,这一切都很好,因为所有规则都适用于所有站点。我最近添加了一个我不想通过所有规则运行的新站点。在执行自己的规则后,有什么方法可以使对该站点的请求突破规则集。

我试过以下没有运气;对 mysite.com 的所有请求都会导致 404。我想我正在寻找的是一个什么都不做的规则,并且被标记为最后一个要执行的规则 [L]。

0 投票
1 回答
4689 浏览

apache - Apache MOD_REWRITE 域级 Cookie

我需要处理我们网站上的会员跟踪。

在我们的 .htaccess 中,我们有:

它创建了一个名为 AFFID 的 COOKIE,其 URL 参数附属公司的值。

但是 Cookie 并不适用于整个域,即转到http://www.domain.com/?affiliate=bmk将 AFFID cookie 设置为 .www.domain.com 的值为 bmk 但我希望 ti 用于.domain.com 以便它可以在我们的安全域中使用,这将是 secure.domain.com

任何帮助,将不胜感激

干杯

0 投票
1 回答
272 浏览

iis - MOD_Rewrite 重写是否通过重写规则调用第二次运行?

当 MOD_Rewrite 执行 RewriteRule 时,是否会为新生成的请求再次执行所有 MOD_Rewrite 规则?具体在以下示例中,这会导致循环吗?

0 投票
24 回答
583552 浏览

.htaccess - 通用 htaccess 将 www 重定向到非 www

我想重定向www.example.comexample.com. 以下 htaccess 代码使这种情况发生:

但是,有没有办法在不硬编码域名的情况下以通用方式做到这一点?