Why does HttpHeader X-Original-URL not exist on so

2019-08-06 08:57发布

问题:

My site using URL Rewrite to make SEO friendly URLs. This makes self-posting a form back to the same page a little tricky.

However in ColdFusion I do this for the form's action attribute:

<form name="formSortBy" method="post" enctype="multipart/form-data" action="#StructFind(GetHttpRequestData().headers, 'X-Original-URL')#">

</form>

The important part here is the #StructFind(GetHttpRequestData().headers, 'X-Original-URL')# which gets me the URL of the page.

However the X-Original-URL key just doesn't exist on some pages so I get an error from ColdFusion saying:

Cannot find X-Original-URL key in structure.
The specified key, X-Original-URL, does not exist in the structure. 

This is happening when I click to go to the homepage of a section I am in. So X-Original-URL exists if I go to http://www.sitename.com/products/gaming but it won't exist if I go just to http://www.sitename.com/products

Is there anyway to get around this or make it work like I need it to?

回答1:

Sounds like there is an issue between your rewrite rules and CF.

But, there is an easy fix - you can get a form to post to itself by simply not specifying the action attribute.