.htaccess - 如何在没有 JS 的情况下获取在浏览器中看到的整个 URL?

标签 .htaccess coldfusion url-rewriting railo bluedragon

我有一个在 ColdFusion 中构建的应用程序,所有请求都将通过 index.cfm 文件运行。

我有一个重写 URL 的 .htaccess 文件。所以,例如......如果我写:

http://domain.com/hello/goodbye/howdy

实际请求总是像这样使用 index.cfm:

http://domain.com/index.cfm/hello/goodbye/howdy

这一切都很好,但现在我被困在如何获取 URL 中的所有内容上。没有一个 CGI 变量似乎不输出 URL 的“/hello/goodbye/howdy”部分。

我试过 cgi.path_info 和 cgi.query_string 等都无济于事……它们只是空白。

我需要抓取域名后面的所有内容,并用它在 CF 中做一些事情。我知道这在 JS 中是可能的,但我真的需要在服务器上使用它。

转储 CGI 范围显示我在这方面没有任何用处:

<cfdump var="#cgi#" />

这是我的 htaccess 文件以供引用:
<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /
RewriteRule ^index\.cfm$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.cfm [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.domain\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

</IfModule>

谢谢。

编辑:

作为附加说明,我还尝试了像这样的底层 Java 方法:
<cfdump var="#getPageContext().getRequest().getContextPath()#" />
<cfdump var="#getPageContext().getRequest().getRequestURL()#" />
<cfdump var="#getPageContext().getRequest().getQueryString()#" />

没有成功:(

最佳答案

<IfModule mod_rewrite.c>

RewriteEngine On
RewriteBase /

RewriteRule ^index\.cfm$ - [L]

RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} !^([^\.]+)\.domain\.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l

#Change exists here:
RewriteRule ^(.*)$ /index.cfm?actualuri=$1 [L,QSA]

</IfModule>

试试 cgi.query_string现在。它应该有 actualuri=/the/path/sent .
此外,按照与上面相同的顺序放置重写规则。

关于.htaccess - 如何在没有 JS 的情况下获取在浏览器中看到的整个 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9292153/

相关文章:

.htaccess - 基于referer的重定向 HTTP_REFERER htaccess

coldfusion - CFWINDOW - 在 CF 中提交表单以留在 CFWindow 中

azure - 如何从 IIS 重定向规则中排除 Azure 插槽

javascript - window.location 未提供正确的 URL

.htaccess - Pagespeed Insights 和 Twitter 嵌入式时间线

.htaccess - 将带有查询参数的动态 URL 转换为静态 URL

.htaccess - 重写规则以添加 .html 扩展名

jquery - CFML Jquery Ajax - 当 cffunction 实际返回 18 时返回零

Coldfusion 10 日期格式问题

javascript - 如何在node.js和express中隐藏URL中的内容但仍然需要发送到服务器?