Solution: How to get CGI.X-Original-URL if it is missing

Hi,

we moved a site to a new server and had a problem: Whenever we called a URL it was redirected to the homepage.

The new server had Lucee6 and Tomcat11 (instead of Lucee5 and Tomcat9) and also needed a new tuckey urlrewrite lib (5.1.3 instead of 4.0).

We first had urlrewrite in suspicion, because some things are different there, but this was not the issue.

After some further investigation we found the problem in system/config/Router.cfc:

function pathInfoProvider( event ) {
		var headers = GetHttpRequestData( false ).headers;
		var uri     = ListFirst( ( headers['X-Original-URL'] ?: (request[ "javax.servlet.forward.request_uri" ] ?: "") ), '?' );
		var qs      = "";
...

While our old Tomcat 9 server had the request variable filled with a proper value, eht variable didn’t even exist in the Tomcat 11 installation.
The cgi.X-Original-URL didn’t exist on both.

We haven’t found the neccessary cahnge in Tomcat, but tried setting the CGI variable in Apache2. And this did the trick.

The solution:
In the host.conf file the following directive must be set:

RequestHeader set X-Original-URL "%{REQUEST_URI}e"

For whatever reason this also didn’t work in our installation, but the follwing hint made it finally working:

RewriteEngine On

# Set X-Original-URL header using rewrite rules  
RewriteRule ^(.*)$ - [E=ORIGINAL_URI:%{REQUEST_URI}]  
RequestHeader set X-Original-URL "%{ORIGINAL_URI}e"

Hope this is helpful.

Best
Michi

2 Likes