Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Current URL

Quote Reply
Current URL
Is there a way to get the current url of a page so it can be used in a tag? I know that you can use javascript using location.href but I assume that this can't be used in a template tag. I also know that on dynamic pages I could use a global and build the URL using environmental variables. However, I would like to get the displayed url - not the rewritten one, the static one on a static site and not the one that is built from during the build process.

Is this possible?
Quote Reply
Re: [afinlr] Current URL In reply to
Maybe this?

<%global%>

Code:
sub {
return $ENV{'SCRIPT_URI'};
}

Not sure if it works, but in theory it should, shouldn't it?

Cheers

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Quote Reply
Re: [Andy] Current URL In reply to
Hi Andy, thanks for the suggestion.

I think this will return the url of the actual script - what I need is the url of the page currently being shown. For example if the url is my homepage - just the domain name - the actual script is page.cgi which I don't want.
Quote Reply
Re: [afinlr] Current URL In reply to
Hi afinlr

Cannot guarantee this but SSI might do what you require. I used to use it to call images into a page based on the url, so I had the same page but depending on what URL you used to get to it would display the appropriate image.

It may be possible to take it one step further and echo the URL BUT when I started developing my links I used ssh but told it was really that advisable in links (due in part possibly to the way it calls globals etc) although I never had any problems.

Might be worth investigating though.

Loosely recalling what i did, as it was a while ago, I had images that were the name of the url, so the image was called www.mypicture.co.uk.jpg
Obviously everything is extension *.shtml
The line to call the image inside te webpage was
<!--#include virtual="$HTTP_HOST.jpg" -->

This then pulled in the url name and added the jpg to display the image

I am not too technical but it's a neat trick and it may be able to go one step further and simply echo the url but I am afraid I can't help you any further.

Actually, just had a thought. You could have a text file with your url name in it. save as www.mytextfile.co.uk.txt then pump in the include virtual but with txt instead of jpg, that would probably do it.Wink

I found shtml and ssi to be a bit tricky sometimes so a good tool I also used was something called ssi.cgi. If you go down this path you will see how useful it is as it gives yoiu the paths you need. SSi only operates in sub folders from the root of the same parent.

This may or may not help but you never know.

good luck!


Cheers
KevM
Quote Reply
Re: [KevM] Current URL In reply to
Hi,

Thanks for all the info. Unfortunately I think that ssi is similar to javascript in that it is processed on the client side and I need something that processes on the server as I need it available in a template tag - I could be wrong? As far as I can see so far, I would need to work out what the url is by hand - I think this might take rather a lot of 'if' statements! It's a shame this isn't available in an environmental variable - it is available on the next page as HTTP_REFERER.
Quote Reply
Re: [afinlr] Current URL In reply to
Quote:
I think that ssi is similar to javascript in that it is processed on the client side and I need something that processes on the server Crazy


Do you want to run that by me again afinlr.........,

Last time I looked SSI stood for Server Side Includes, this is not the same as a client side JScript includes function which I also have somewhere and actually works in a subtly different way as you stick your info (the images or text) into one folder that the JS calls. SSi doesn't work like that, it's relative and, as the name implies, server side.

You can still call it in a template tag, i call several scripts into a template tag, if you think about it the tag could be called url with <!--#include virtual="$HTTP_HOST.jpg" --> (or as discussed, .txt) so you simply call <%url%>

rgds

made me smile!!

Cheers
KevM
Quote Reply
Re: [KevM] Current URL In reply to
Sly - brain not working. I'll have another think about that!
Quote Reply
Re: [KevM] Current URL In reply to
(Obviously!) I've never used SSI before - and I certainly don't want to have to rename my files to have an .shtml extension. I assume that there must be a way to use SSI on html pages by editing the httpd.conf file in some way? Any ideas?
Quote Reply
Re: [afinlr] Current URL In reply to
Hello afinlr,

when I was getting to grips with links I had a few different build folders before i went live. It is, I thought, quite nifty that you can go to setup and tell it to build with whatever extension you want so changing to *.shtml isn't too difficult, you just tell it to use a different extension, rebuild and there it is.

Overall, from previous posts, I think your knowledge is far greater than mine for code etc so I really don't think SSI would cause you a problem, it's pretty much the same as all the globals tags in Links but you need to have *.shtml on the end.

The other thing that can trip you up is remembering that ssi only works in parent>child i.e you cannot <!include> a file from another website etc.

I would suggest having a play with another page in your directory to see how it works for you, editing the httpd.conf file is a whole new ball game and not something I have been involved in. I could be wrong but I don't think editing it will help, I honestly do not know though.

Cheers
KevM
Quote Reply
Re: [KevM] Current URL In reply to
I think I may have hit a block already - all my pages are dynamic - i.e. using cgi files so I don't think I can use SSI? And this was looking very hopeful Frown
Quote Reply
Re: [afinlr] Current URL In reply to
Yes, look at the httpd.conf file for shtml and add a line for html that looks just like it.

Also, with dynamic, you can imitate SSI with <IMG> tags, or <%globals%>, and using globals, you have much, much more power.

You can put your globals in separate files, in the Plugins:: area, and call them as functions.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Current URL In reply to
Thanks Pugdog. I do have some experience of writing globals but I can't see how to get the current url of the page - any ideas?
Quote Reply
Re: [afinlr] Current URL In reply to
What about $ENV{SERVER_NAME}/$ENV{REQUEST_URI}


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Current URL In reply to
If only it were that easy. I want the url of the actual request in the browser address bar and all my urls are rewritten. This just returns the url of the underlying script.
Quote Reply
Re: [afinlr] Current URL In reply to
Did you print out the full values of the $ENV hash your server has?

There are some DOCUMENT values that some servers are returning now, that give the URL of the document.

The problem is that if the request is rewritten, the location that stores the value may be rewritten.

The only thing I could envision, at that point, if the $ENV string is not kept, then is to grab the URL before it's rewritten, and pass it as a parameter.

RewriteRule (.*) /cgi-bin/LinkSQL/page.cgi?g=$1

Will put the value of the URL into the $1 variable.

Adding [E=ORIGINAL_URL:$1] will write out a new $ENV variable ORIGINAL_URL with the value of $1

According to the mod_rewrite docs

Quote:
Environment Variables[/url]This module keeps track of two additional (non-standard) CGI/SSI environment variables named SCRIPT_URL and SCRIPT_URI. These contain the logical Web-view to the current resource, while the standard CGI/SSI variables SCRIPT_NAME and SCRIPT_FILENAME contain the physical System-view.
Notice: These variables hold the URI/URL as they were initially requested, i.e., before any rewriting. This is important because the rewriting process is primarily used to rewrite logical URLs to physical pathnames.
Example:
SCRIPT_NAME=/sw/lib/w3s/tree/global/u/rse/.www/index.html SCRIPT_FILENAME=/u/rse/.www/index.html SCRIPT_URL=/u/rse/ SCRIPT_URI=http://en1.engelschall.com/u/rse/



An explanation of available flags (brief)

Quote:


Rewrite Rule
Syntax: RewriteRule url-pattern url-new [[flag,...]]
Example: RewriteRule ^/foo/(.*)$ /bar/$1 [R,L]
Since: Apache 1.2

This directive is the real rewriting workhorse. It can occur more than once. Each directive then defines a single rewriting rule. The definition order of these rules is important, because it is used when applying the rules at runtime. The url-pattern is a regular expression that is applied to the current URL, where ``current'' means at the time when this rule is applied. The current URL may not be the original requested URL, because any number of rules could have already matched and altered it.

The url-new argument is the string that is substituted for the original URL matched by the url-pattern. Beside plain text, you can use back-references ($N) to the url-pattern, back- references (%N) to the last matched RewriteCond pattern, server variables such as RewriteCond test strings (%{NAME}), and mapping function calls (${map-name:look==up-key|default-value}) for this argument.

In addition, you can set special flags for url-new by appending one or more flag arguments. The flag argument is actually a comma-separated list of the following flags: redirect (or R) to force an HTTP redirect; forbidden (or F) to forbid access; gone (or G) to eliminate the URL; proxy (or P) to pass the URL to mod_proxy; last (or L) to stop processing; next (or N) to start the next round of processing; chain (or C) to chain the current rule with the following one; type (or T) to force a particular MIME type; nosubreq (or NS) to ensure that the rule applies only if no internal sub-request is performed; nocase (or NC) to force the URL matching to be case-insensitive; qsappend (or QSA) to append a query string part in url-new to the existing one instead of replacing it; passthrough (or PT) to pass the rewritten URL through to other Apache modules; skip (or S) to skip the next rule; and env (or E) to set an environment variable. For more details, see the mod_rewrite online documentation.


PUGDOG� Enterprises, Inc.

The best way to contact me is to NOT use Email.
Please leave a PM here.
Quote Reply
Re: [pugdog] Current URL In reply to
Thanks Pugdog.

I did find the ENV flag last night and had a play around with it - but I couldn't get it to feed into the page for some reason. I wrote a global that returned all the available environmental variables and there is nothing suitable there and after adding the E flag the extra variable didn't appear. I'm not sure whether that is because of other flags I'm using or mod_proxy etc - I'll try some more experiments with this and see whether I can get it to feed into any pages.

Thanks for taking the time to think about this, I appreciate it.

Laura.
The UK High Street
Quote Reply
Re: [afinlr] Current URL In reply to
Hello Laura,

I would like to know if you found a solution?

I would like to find the current URL .

Thank you for your answer.

Mick
Quote Reply
Re: [mick31] Current URL In reply to
No, sorry. I didn't find a solution.