質問

I have an application I'm building in ColdFusion, whereby all requests will run through the index.cfm file.

I have a .htaccess file that rewrites the URL. So, for example...if I write:

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

The actual request always uses index.cfm like so:

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

This all works great, but now I'm stuck with how I can grab everything that is in the URL. Not one of the CGI variables don't seem to output the "/hello/goodbye/howdy" part of the URL.

I have tried cgi.path_info and cgi.query_string etc to no avail...they're just blank.

I need to grab everything that comes after the domain name, and do stuff in CF with it. I know it's possible in JS, but I really need this on the server.

Dumping the CGI scope shows me nothing useful in this regard:

<cfdump var="#cgi#" />

Here's my htaccess file for reference:

<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>

Thanks.

EDIT:

As an additional note, I've also tried the underlying Java methods like so:

<cfdump var="#getPageContext().getRequest().getContextPath()#" />
<cfdump var="#getPageContext().getRequest().getRequestURL()#" />
<cfdump var="#getPageContext().getRequest().getQueryString()#" />

To no success :(

役に立ちましたか?

解決

<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>

try cgi.query_string now. It should have actualuri=/the/path/sent.
Also, put the rewrite rules in the same order as put above.

他のヒント

Check #CGI.REQUEST_URI# - it's undocumented but works

I hope this is what you are looking for.

  <cfset link = "http://" & GetHttpRequestData().headers['host'] & GetHttpRequestData().headers['X-REWRITE-URL'] >

I think the simplest means is to actually look at the CGI.PATH_INFO field.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top