Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change query string from "?" to "/"

Status
Not open for further replies.
ColdFusion can't do this natively... you have to build your own code to do it.

Basically, you want the URL to look something like:
Code:
[URL unfurl="true"]www.mydomain.com/index.cfm/id=0332/data=2234[/URL]

But ColdFusion won't plug your variable values into the URL scope, of course, so you need to use one or more of the CGI scope variables. Unfortunately, the web server won't even consider this a query string so you can't just look at
Code:
#CGI.QUERY_STRING#
. And to make matters worse, servers aren't particularly consistent in how they fill in the CGI variables... so you kind of have to hunt-and-peck for the proper ones to use for your particular server and setup.

A common set is:
Code:
<CFSET nVarLen=Len(CGI.PATH_INFO)-Len(CGI.SCRIPT_NAME)>
<CFSET sQueryString=Right(CGI.PATH_INFO, nVarLen)>
and that's a pretty good place to start.
But, for example, CGI.PATH_INFO only returns the &quot;/id=0332/data=2234&quot; portion of the URL on my server... instead of the entire URI it's supposed to contain.

Anyway... some combination of CGI variables are going to give you just the pseudo &quot;query string&quot; (just do
Code:
<CFDUMP var=&quot;#CGI#&quot;>
to help figure out which one(s)).

Once you have that, then you would do something like:
Code:
<CFLOOP list=&quot;#sQueryString#&quot; index=&quot;whichVarPair&quot; delimiters=&quot;/&quot;>
   <CFSET &quot;#ListFirst(whichVarPair,&quot;=&quot;)#&quot; = ListLast(whichVarPair,&quot;=&quot;)>
</CFLOOP>

Now
Code:
#id#
is going to contain &quot;0332&quot;, etc.



-Carl
 
Carl,

Not sure how much it matters for search engines, but as with this site if you are not logged in as a member the url is

And my guess it that this is done for search engines. I have seen this link usage without the &quot;=&quot;. How much would change in the above example.

Thanks

Scott
 
Hi mate,

I found the following code when trying to find a way to do this.
Code:
<cfscript> 
//first get everything after the script file 
qstring = replace(CGI.path_info,CGI.script_name,&quot;&quot;); 

//next loop through each variable and set them accordingly 
for(i=1; listlen(qstring,&quot;/&quot;) GTE i; i=i+1){ 
if(i MOD 2){ 
qstringvariable = listgetat(qstring,i,&quot;/&quot;); 
}else{ 
&quot;URL.#qstringvariable#&quot; = listgetat(qstring,i,&quot;/&quot;); 
} 
} 
</cfscript>

This code works without problem on my server, I'm still learning CF so if anyone more knowledgable can see any problems with it, I would be very interested to hear about them.

Hope this helps

Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
It would make it just slightly more complex because you wouldn't be able to rely on the &quot;=&quot; to be a delimiter.

But you would do something like:
Code:
<CFLOOP from=&quot;1&quot; to=&quot;#ListLen(sQueryString)#&quot; index=&quot;elementCounter&quot; delimiters=&quot;/&quot; step=&quot;2&quot;>
   <CFSET nNamePosition = elementCounter>
   <CFSET nValuePosition = elementCounter+ 1>
   <CFSET &quot;#ListGetAt(sQueryString,nNamePosition ,&quot;/&quot;)#&quot; = ListGetAt(sQueryString,nValuePosition,&quot;/&quot;)>
</CFLOOP>

You'd, essentially, have to step through the query string by twos, and assume the first element was the variable name and the second was the value. This isn't always a safe assumption... you have to be very careful how you build your new query string. And make sure that you never put NULL values in the elements... otherwise you'd get something like
Code:
somepage.cfm/var1/100/var2/200/nullvar//var4/400
and if you use ColdFusion's built-in list functions (as above), they'd completely ignore the empty element and your entire list would then be off by one.

The alternative would be to find the positions of the &quot;/&quot;'s yourself and step through them manually. This would avoid the potential of having NULL values corrupt your data... but it's also more code and more frustrating.



-Carl
 
Hi guys,

I am also trying to optimize a clients site for search enignes and I, too, was worried that a dynamic site would not get listed in search engines. That is what I read on this site though

I have also read that if you have a variable that is more than two characters long in the URL the search engines will have problems indexing your site.
..and that if you place more links on your site you get a higher rating.
Any comments??

When I read on this forum it seems like the most of you believe that a dynamic link is indexed as much as a static. Is it worth going through and change the links in the template as Owen Knapp's SES URL tutorial ??

Confused
Jonas
 
No, it's not worth it. In fact, it's a waste of time. This whole idea that search engines can't index dynamic url strings is a load of bull. I've had url strings that have been Encrypted and UrlEncoded, and search engines have indexed them just fine.

I just went to Yahoo! and ran a search on "ECAR Technologies", and this was the third link that showed up:
Code:
www.ecartech.com/hosting_plans.cfm?T=(0VL>$)B.NW<+%0A
I never even submitted my site to Yahoo!, it just found and indexed it on it's own, dynamic urls and all!


Hope This Helps!

ECAR
ECAR Technologies, LLC

"My work is a game, a very serious game." - M.C. Escher
 
No, it's not worth it. In fact, it's a waste of time. This whole idea that search engines can't index dynamic url strings is a load of bull. I've had url strings that have been Encrypted and UrlEncoded, and search engines have indexed them just fine.

It isn't that they won't index the site, the spider is just likely to be more cautious when it does encounter a dynamic site to prevent itself getting stuck in a loop. If you have a large site, using SEO friendly URLs would normally result in more of your pages getting indexed.

Wullie

Fresh Look - Quality Coldfusion/Windows Hosting

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
site: in Google says you have 15 pages.

site: in Yahoo says you have 8 pages.

site: in MSN has 13 pages.

Which SE is right? Maybe none of them if you have other pages with variables.

The main issues comes to getting all pages of a site indexed when pages with multiple(more than 2) variables are linking to other pages with multiple variables. (like Wullie said an endless loop, such as a calander app that could continue forever) Crawlers appear to index deeper content when a site is more popular (Higher PR/more Inbound Links).

johk02

Its not if you have a variable that is more than 2 Characters(haven't heard that before), but it is recommended that you have 2 or less variables in the URL (ex. viewthread.cfm?qid=640165&page=1 )

My site is a Coldfusion site even though most of the pages appear to be .htm pages. I am using a custom 404 page pulling vars from the URL. It gets crawled deeply all the time. Other sites built on the same CF_Nuke application, have much fewer pages indexed then they have.

xtendscott
Web Site Design | Cryosurgery | Walla Walla Portal
 
Interesting:
I was just noticing that I started this thread just over two years ago.

Search Engines have gotten much better about variables in the URL, but I still feel there is an advantage to keep it minimal to none.

xtendscott
Web Site Design | Cryosurgery | Walla Walla Portal
 
Carl, Good to see you back.

I'm with Ecar on this one. Coding that way for Search engines is more or less a waste. As xtendscott just said "Search engines have gotten much better about variables in the url." At some point probably in the near future this will be a moot issue.

We already find ourselves cautious of what we can do to be compatible with older browsers, to follow the same caution for SE's is nonsence.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
We already find ourselves cautious of what we can do to be compatible with older browsers, to follow the same caution for SE's is nonsence.


Thats one of the dumbest comments I have heard.

If you are a web developer for clients that expect you to provide the best product for them, you are doing a disservice to the client not to take SE's as a major factor in the way you create the product.

Clients that are not terribly internet aware have no clue and I feel it is my responsibility to design in a way I know that the SE's will actually crawl their sites.

I guess you would think that it is "Nonsence" for Amazon to have SE Friendly URL's.

Macromedia -
MSN -
DMOZ.org -
These are some of the larger sites on the net and according to your comment, they shouldn't waste their time with that. MSN is a Search Engine and they do it.

Results 1 - 10 of about 866 - Google site:http://www.mycfnuke.com&hl=en]Google Cache of a MyCFnuke.com page[/url] - Agreed that the page is indexed by Google, but look at the cache date,"as retrieved on Jan 27, 2005", even if Google will visit the page, it doesn't look like they go back often. What if the page has been updated since then?

Yahoo - Results 1 - 17 of about 48 for site:www.mycfnuke.com
Looks like Yahoo is missing 800+ pages from what Google has.

Page 1 of 84 results containing site:www.mycfnuke.com

I hope you don't do developement on the web for clients, if so you should have a warning sign on your site saying, "Warning - My web developing practices may keep many of your informational pages out of search engines".

Just my take on the subject. You can do what you want.

xtendscott
Web Site Design | Cryosurgery | Walla Walla Portal
 
"Warning - My web developing practices may keep many of your informational pages out of search engines"

are you providing information or being hostile? Take a deep breath and count to 10 before you try cutting me down at the knees, you don't even know me or my work. that's uncalled for.

I rarely use sites with more than 2 url variables anyway, when i do it usualy on an intranet so it doesn't matter.

Its funny to see the search engines that we code so friviously to be friendly to don't code thier urls to the same methodology. (admitidly they're not woried about being indexed)

yahoo results for Coldfusion:
google:
MSN:
a9.com is the only one that did, which is, as you pointed out above amazon.
for the record i didn't say you wouldn't get better results right now, at this point in time. I suggested this is a temp work around for something the SE's will have worked out in the semi-near future.

as for your examples above. i've never had much faith in yahoo or MSN, results are sketchy and lacking, as you've demonstrated.

P.S. I didn't see you argue the older browser comment. are we to assume you do your clients the unjustice of not coding for the 1% of users left using 4th gen browsers?


We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
TruthInSatire- I do appologize for being a bit reactive.

I rarely use sites with more than 2 url variables anyway, when i do it usualy on an intranet so it doesn't matter.

Adding this comment to the prior post would have clarified a lot. People come here for answers answers and I felt that what was said was terribly incorrect as the difference in SE's show with a site that contains many URL Vars.

Saying that MSN and Yahoo are "lacking", doesn't change that together(with their search networks) make up almost 40-50% of search traffic. I won't bet on how they MAY do things in the future. MSN is also looking at purchasing AOL, which would take a chunck of search traffic from Google.

It also sounds like you try to maintain a minimal # URL Vars in the URL if the app is on the Web. This may be just your style or you are cognisent of the fact that SE's may have issues with more.

Your Search for "ColdFusion" also somewhat proves my point, as you notice in the search results, rarely do you see a URL with a ?var=this.

As for older browsers, Yes I try to make sites as compatible as possible with ROI in mind. CSS design, still displays in old browsers, but not as pretty. Much like the old days. :)

xtendscott
Web Site Design | Cryosurgery | Walla Walla Portal
 
Well, now that we got that out of the way... :)

Have you ever told a user, "your browser doesn't support this web page, download this one instead". no probably not. My reasoning is the SE's will most likely solve this problem for 3 reasons.

1) Not fixing it would be the SE telling millions of websites "nope, you're going ot have to change", just like us telling a user to use a different browser.

2) the standard for passing data in the URL is currently and has been ?x=1&y=2&z=3... for a LONG time. unless the SE's move to change that they will have to learn to read it. and if it IS changed you'll run into the same problem. using / instead of ? & tricks the SE into thinking its a static page to its more gullible to end up in a loop. changing the standard would cause the same problems.

3) finaly, websites are more and more dynamic. Not solving this issue would cause the SE to fail. I remember when altavista used to be the bomb SE. Well, it didn't keep up with technology... so this will have to be solved for the sucess of the SE, not just a "nice thing to have"

3

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Sounds like we agree more than we disagree. ;)

Part of the issue is poor programming practices such as page.cfm?var1=1&var2=2&var3=3 is a different page to SE's from page.cfm?var2=2&var1=1&var3=3 even though they produce the same results on the server. On one page a the programmer may use the first example and on another they may use the second. This creates "duplicate content".

Another is the "Endless" loop senario and they may have limits to how many levels of links they follow.

THe SE's solutions so far are for sites to do "Paid Inclusion"-Yahoo, and Google now has its XML sitemap standard. This gets your content indexed, but doesn't guarentee listing in results.

On Apache there is Mod_rewrite and on some servers/hosts they may let you use ASAPI_rewrite to make the url follow a more directory like structure. But with proper coding practices keeping the URL vars structured and minimal in #, there is normally good crawls from SE's.

But as of right now, I would still keep in mind the limitations of SE's on Web accesible projects for clients.

xtendscott
Web Site Design | Cryosurgery | Walla Walla Portal
 
TruthInSatire said:
Its funny to see the search engines that we code so friviously to be friendly to don't code thier urls to the same methodology. (admitidly they're not woried about being indexed)

yahoo results for Coldfusion:
google:
MSN:

You are actually quite far off the mark on this one. All of the examples you provided actually deny robots from accessing the search results in their robots.txt. It's not that they are not worried if they get indexed, it is that they do not want those pages to be indexed.

Now, go onto a page that they do not block spiders from and look at the URL format:

Google:


Yahoo:


So in essence, these engines do use search engine URLs in the places that they allow spiders to index.

Hope this helps

Wullie

Fresh Look - Quality Coldfusion/Windows Hosting

The pessimist complains about the wind. The optimist expects it to change. The leader adjusts the sails. - John Maxwell
 
the google page could quite possible be a static page, this example doesn't exactly support your argument. google suggests you create static pages in place of dynamic ones when url variables are needed. (yeah right). i don't see much data that could be dynamic anyway.

yeahpoo uses same idea carl had waaaay up there, post number 2, which in turn was questioned in post 3 and quicky abandoned. I wonder if that says anything about what yeahpoo accepts compared to other SE's

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top