Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the ENTIRE URL as seen in the browser without JS?

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

like image 338
Michael Giovanni Pumo Avatar asked Dec 27 '22 06:12

Michael Giovanni Pumo


2 Answers

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

like image 61
ThinkingMonkey Avatar answered Jan 03 '23 11:01

ThinkingMonkey


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

like image 30
Jura Khrapunov Avatar answered Jan 03 '23 10:01

Jura Khrapunov