I'm looking for an SSI Environment Variable that can return the Document URL...
http://www.mySite.com/path/myPage.html
Right now, I'm cobbling it together using these other environment variables...
<!--#echo var="SERVER_NAME" -->
gives this: http://www.mySite.com, and...
<!--#echo var="DOCUMENT_URI" -->
gives this: /path/myPage.html.
So I'm putting them both together, like this...
http://<!--#echo var="SERVER_NAME" --><!--#echo var="DOCUMENT_URI" -->
And it works just fine.
Two questions:
1) Is there a single SSI Environment Variable for the full Document URL? I've been searching for a while but cannot seem to find.
2) If not, can somebody explain why? There is one called HTTP_REFERER that returns the full URL of the referer, so why not one that returns the full URL of the current location, something like a DOCUMENT_URL?
1) No, there isn't. You can check this by a simple dump of all environment values:
<pre>
<!--#printenv -->
</pre>
2) Why? I'm not sure, perhaps because it would be redundant to have that in a single variable where you can cobble it together as you did. That and the fact that you might want to also do certain things like ignore the server protocol (HTTP or HTTPS) or use a different port, or any number of other reasons.
Hope that helps
Related
I'm working on a Pylons project using Jinja2 templating. I want to test for the request URI and/or controller inside the Jinja2 templates - is there an equivalent to a getRequestUri() call? I can set a context variable as a flag inside all the controller methods to do what I want, but that seems a bit like writing my home address on each and every one of my house keys... i.e. not quite the right way to do it.
Solution: not quite a function call, but I can test against url.environ.PATH_INFO. It only gives me the URL path, not the hostname, and I don't know that it would give me the query string, but it gives me what I need.
I'm updating a site and am struggling to find a way to get an id from the URL. For example I have this:
http://some.html/search.cfm?id=9900000000301
How do I get the id value "9900000000301" from the URL in Coldfusion8?
I have tried url.id plus all sorts of *cgi.query_string* variations, but the number is still out of reach :-(
Thanks for help!
EDIT:
If I dump the URL struct, I'm getting this:
catch - struct
TYPE: default
VALUE: search
Which is not saying much to me.
The url.id should work just fine.
Url.Id will work - with one exception.
If you have created a variable called Url, it is possible (in Adobe CF) to "hide" the Url scope, and thus not be able to access it.
For example, if you have a function with an argument called url, referring to url inside that function will refer to Arguments.Url, not the Url scope. If this is the case, you need to rename the argument to be able to access the proper Url scope.
(Alternatively, switch to a better CFML engine where scope names always takes precedence over unscoped variables, and thus scopes cannot be hidden.)
Depending on how you are looking to use the data, here are two examples. The first checks to see if it was defined and the second sets a variable to the value.
<cfif isDefined("URL.id")>
<cset myVariable = URL.id>
</cfif>
Hope this helps!
I have a relatively simple (I think) use-case but I can't find any examples where someone has done this. We are using Varnish as a cache and reverse proxy in front of two different applications and would like to make things a bit more unified across both as they both do similar things. I was hoping Varnish could help rewrite the URLs as shown below.
Original application URL for pagination (get first 10 items):
http://myapplication.com/products/?startindex=1&endindex=10
Desired URL:
http://myapplication.com/products/?paginate=1:10
This is just one example (the most complex because it combines two parameters), but in all cases the input values for the parameters stay the same, it is just that the parameter names will change.
Another example would be:
http://myapplication.com/search/?query=something
to:
http://myapplication.com/search/?q=something
Does anyone have any experience with varnish and how this could be done?
Thanks
Apparently you can. The answer is that regsub is your friend.
For example:
if (req.url ~ "(.*)(id=)") {
set req.url = regsub(req.url, "(feeds/[a-zA-Z]*/)(.*)([\?|&])(id=)([a-zA-Z0-9]*)(.*)", "\1\2\3byGuid=\5\6");
}
This will convert and incoming "id" parameter into a "byGuid" parameter on the backend. t also does a bunch of stuff with the rest of the URL string but the basics are there. SO if anyone wants to do something similar this is a good starting point.
I am reworking on the URL formats of my project. The basic format of our search URLs is this:-
www.projectname/module/search/<search keyword>/<exam filter>/<subject filter>/... other params ...
On searching with no search keyword and exam filter, the URL will be :-
www.projectname/module/search///<subject filter>/... other params ...
My question is why don't we see such URLs with back to back slashes (3 slashes after www.projectname/module/search)? Please note that I am not using .htaccess rewrite rules in my project anymore. This URL works perfect functionally. So, should I use this format?
For more details on why we chose this format, please check my other question:-
Suggest best URL style
Web servers will typically remove multiple slashes before the application gets to see the request,for a mix of compatibility and security reasons. When serving plain files, it is usual to allow any number of slashes between path segments to behave as one slash.
Blank URL path segments are not invalid in URLs but they are typically avoided because relative URLs with blank segments may parse unexpectedly. For example in /module/search, a link to //subject/param is not relative to the file, but a link to the server subject with path /param.
Whether you can see the multiple-slash sequences from the original URL depends on your server and application framework. In CGI, for example (and other gateway standards based on it), the PATH_INFO variable that is typically used to implement routing will usually omit multiple slashes. But on Apache there is a non-standard environment variable REQUEST_URI which gives the original form of the request without having elided slashes or done any %-unescaping like PATH_INFO does. So if you want to allow empty path segments, you can, but it'll cut down on your deployment options.
There are other strings than the empty string that don't make good path segments either. Using an encoded / (%2F), \ (%5C) or null byte (%00) is blocked by default by many servers. So you can't put any old string in a segment; it'll have to be processed to remove some characters (often ‘slug’-ified to remove all but letters and numbers). Whilst you are doing this you may as well replace the empty string with _.
Probably because it's not clearly defined whether or not the extra / should be ignored or not.
For instance: http://news.bbc.co.uk/sport and http://news.bbc.co.uk//////////sport both display the same page in Firefox and Chrome. The server is treating the two urls as the same thing, whereas your server obviously does not.
I'm not sure whether this behaviour is defined somewhere or not, but it does seem to make sense (at least for the BBC website - if I type an extra /, it does what I meant it to do.)
hi is there a wait to load a full url.?
url= 'http://www.example.com/whatever.php'
$('#selector').load(url); // this way returns null (empty result)
instead of :
url = 'whatever.php'
$('#selector').load(url); // works fine
Some may think whats the difference i want to use this because im using multiple directories. so i could be on a page like...
example.com/dir/
but the dir folder will not have the whatever.php
so anyone has a fix for this that i should always use the full url?
thank you.
You could always use relative paths
putting / before the path will tell the browser to go the root of the page. For your example you could call /whatever.php.
You can also move up one directory at a time. Lets say you are in a page at http://www.example.com/dir/foo/bar.php and want to access something in the dir folder, you could specify ../inTheDir.php to move up one directory or ../../inTheRoot.php to move up two.
This should work for you, but based on your comment it sounds like you have a problem somewhere else since your www. page doesn't seem to respond correctly.
No, there isn't.
If http://www.example.com/ takes longer to load than http://example.com/ then it is probably because you have the DNS record for example.com cached but not the record for www.example.com.
Corrected after having realized a typo changed the meaning of the question.:
This is a case of having a mismatch between the host name the page is loaded from and the host name the Ajaxed resource is requested from. i.e. The Same Origin Policy.
Pick a host name to be canonical, use that one in your requests, and redirect (with a 301 status code) from the other so that people don't go to the wrong one by mistake.