Self-executing anonymous functions and MOD_REWRITE

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Self-executing anonymous functions and MOD_REWRITE

Postby TomXampp » 13. March 2015 19:40

I had begun a discussion of this on a different thread, but I've now found what seems to be the exact cause of my problem:

I have a file that relies on a self-executing anonymous Javascript/JQuery function to make the page's content appear. When I load the file directly, like this:

mysite/x.html


...then the page loads and everything displays. However, if I use even the simplest RewriteRule to fetch it without changing the URL, like this:

Code: Select all
RewriteRule ^g$ /x.html [NC,L]


...then the code is served to the browser when I enter:

Code: Select all
mysite/g


...(viewing the source confirms this) but the self-executing anonymous script function does not execute, and so only a blank page appears in the browser (there are no PHP errors, etc.; I've checked all of the logs).

However, appending an R flag to the RewriteRule, like this:

RewriteRule ^g$ /x.html [NC,L,R]


...allows the page to execute. The problem, however, is that "X.HTML" now appears in the URL bar; I want the "G" to remain in the URL bar.

How do I force MOD_REWRITE to allow self-executing anonymous functions to execute when the page is gotten by internal redirection?
TomXampp
 
Posts: 28
Joined: 12. March 2015 03:58
Operating System: Windows 8.1

Re: Self-executing anonymous functions and MOD_REWRITE

Postby gsmith » 13. March 2015 20:33

If the javescript inside the html file, doubtful you can.
If the javascript is in a separate file (like .js) that's included in the html with the script tag then you could treat that file separately with two rewrite rules, using RewriteCondition to not act on the .js in the main rule, then do the opposite in another rule that just acts on the .js file. Or simply just not act on the .js at all in the main rule if that is what is needed.

Rewriting is an art form, so much so it even has a website dedicated to it;
http://www.modrewrite.com/
gsmith
 
Posts: 194
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win XP to 2012R2/VS 6,9,11,14

Re: Self-executing anonymous functions and MOD_REWRITE

Postby Nobbie » 13. March 2015 20:58

I dont think its a question of mod_rewrite. Without having any knowledge about your coding, there might be a difference between HTTP_REFERER or somewhat else. JavaScript is executed by the browser (without any influence of Apache/PHP etc.) and a script is a script is a script - all Apache actions (like mod_rewrite) or any PHP code are already executed and finished, before the browser receives HTML/JS. Apache does not know anything about JavaScript, vice verse the browser does not know anything about PHP.

Seems you have a fairly complicated infrastructure and lost control of it...
Nobbie
 
Posts: 8769
Joined: 09. March 2008 13:04

Re: Self-executing anonymous functions and MOD_REWRITE

Postby gsmith » 14. March 2015 01:55

Good point Nobbie!
gsmith
 
Posts: 194
Joined: 29. November 2013 18:04
Location: San Diego
XAMPP version: 0.0.0
Operating System: Win XP to 2012R2/VS 6,9,11,14


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 56 guests