Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-pascal / 2010-07

Search Engine friendly CGI web apps and pages

8 messages · 4 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

Google and probably most other search engines don't index website that have URL's in the following format:

http://localhost/mycgi?action=myaction

Basically parametrized URL's containing ? or = characters.

What do I need to do in my CGI program to create Search Engine friendly URL's? Note that I'm not using some fancy framework like fpWeb, just plain old CGI (console type) app.

For example, changing the above URL to something like:

http://localhost/mycgi/myaction

'mycgi' being the CGI application
'myaction' being the parameter passed to the CGI app.

My got a custom written (very basic) wiki, which uses the format of the first URL show, and would like to change my CGI wiki app to use Search Engine friendly URL's so my wiki pages can be indexed by Google.

PS:
Please note, I'm not really into web development, so sorry if this is a dumb sounding question. :)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 29 lines
Hi, Google and probably most other search engines don't index website that have URL's in the following format: http://localhost/mycgi?action=myaction Basically parametrized URL's containing ? or = characters. What do I need to do in my CGI program to create Search Engine friendly URL's? Note that I'm not using some fancy framework like fpWeb, just plain old CGI (console type) app. For example, changing the above URL to something like: http://localhost/mycgi/myaction 'mycgi' being the CGI application 'myaction' being the parameter passed to the CGI app. My got a custom written (very basic) wiki, which uses the format of the first URL show, and would like to change my CGI wiki app to use Search Engine friendly URL's so my wiki pages can be indexed by Google. PS: Please note, I'm not really into web development, so sorry if this is a dumb sounding question. :)

When using cgi or FastCGI, the PATHINFO environment variable contains the /myaction part - in fact, it contains whatever the server finds after the path to the CGI app.

If you'd do http://localhost/mycgi/myaction/myvariable/myvalue, then PATHINFO would contain myaction/myvariable/myvalue, and you can then parse and use that.

fpweb does the same.

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt

Op 2010-07-13 15:21, Michael Van Canneyt het geskryf:

When using cgi or FastCGI, the PATHINFO environment variable contains the /myaction part - in fact, it contains whatever the server finds after the path to the CGI app.

Thanks Michael.

I tried what you suggested but ran into a problem - that environment variable doesn't exist here. I Googled it and I found a website that mentions PATH_INFO environment variable instead. That worked. Thanks for the info.

BTW:
Just so others know, if you call the CGI app directly without any parameters, PATH_INFO is not set as an environment variable. Just another little web gotcha! :)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email

Michael Van Canneyt
to Graeme Geldenhuys
Graeme Geldenhuys wrote 12 lines
Op 2010-07-13 15:21, Michael Van Canneyt het geskryf: > > When using cgi or FastCGI, the PATHINFO environment variable contains the > /myaction part - in fact, it contains whatever the server finds after the > path to the CGI app. Thanks Michael. I tried what you suggested but ran into a problem - that environment variable doesn't exist here. I Googled it and I found a website that mentions PATH_INFO environment variable instead. That worked. Thanks for the info

It was a typo, my mistake. The fp-web property is PathInfo :/

Show quoted text 5 lines
BTW: Just so others know, if you call the CGI app directly without any parameters, PATH_INFO is not set as an environment variable. Just another little web gotcha! :)

Well, to make things more complicated, newer apache servers allow to disable PATH_INFO passing to CGI scripts alltogether. I guess it is to protect against search engines flooding the CGI scripts. Exactly the opposite of what you want to achieve :-)

Michael.

Reply by email

Graeme Geldenhuys
to Michael Van Canneyt
Michael Van Canneyt wrote
Well, to make things more complicated, newer apache servers allow to disable PATH_INFO passing to CGI scripts alltogether. I guess it is to protect against search engines flooding the CGI scripts. Exactly the opposite of what you want to achieve :-)

I always seem to follow the path with most resistance. :-) Luckily I control the web server setup here.

While we are on the topic of CGI and Apache. Any idea how to tell Apache that a specific file is a CGI program, even though that file has no file extension like the obvious .cgi suffix? This is not to serious - I think Google accepts URLs with a '.' (dot) in the path. eg: http://www.mydoman.com/mmaths/project1.cgi/myparam

More searching on Google revealed one forum post mentioning this...but the author wasn't sure if it works. I couldn't get it to work. :-(

'project1' is my CGI application.

------------ .htaccess ------------------
<Files project1>
AddHandler cgi-script
</Files>
---------------------------------------

Regards,   - Graeme - _______________________________________________ fpGUI - a cross-platform Free Pascal GUI toolkit http://opensoft.homeip.net/fpgui/

Reply by email

Felipe Monteiro de Carvalho
to Graeme Geldenhuys

In the standard Apache setup it will thread anything you put in the cgi-bin directory regardless of the extension as a cgi program. The path to this is set in httpd.conf here:

#
# ScriptAlias: This controls which directories contain server scripts. # ScriptAliases are essentially the same as Aliases, except that # documents in the target directory are treated as applications and # run by the server when requested rather than as documents sent to the # client. The same rules about trailing "/" apply to ScriptAlias # directives as to Alias.
#
ScriptAlias /cgi-bin/ "C:/Program Files/Apache Software Foundation/Apache2.2/cgi-bin/"

Felipe Monteiro de Carvalho

Reply by email

Zaher Dirkey
to Graeme Geldenhuys: I always seem to follow the path with most resistance. :-) Luckily I control the web…
Graeme Geldenhuys wrote 9 lines
While we are on the topic of CGI and Apache. Any idea how to tell Apache that a specific file is a CGI program, even though that file has no file extension like the obvious .cgi suffix? This is not to serious - I think Google accepts URLs with a '.' (dot) in the path. eg: http://www.mydoman.com/mmaths/project1.cgi/myparam

in .htacces with rewrite mode is enabled, it easy to convert new style to old one

RewriteEngine on

RewriteRule ^$ project1.cgi [L] RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) project1.cgi?action=$1 [QSA,L] RewriteRule ^project1.cgi$ project1.cgi

And you have many examples on internet to understand RewriteEngine

Thanks

Zaher Dirkey

Reply by email

Graeme Geldenhuys
to Felipe Monteiro de Carvalho: In the standard Apache setup it will thread anything you put in the cgi-bin directory…

Op 2010-07-13 17:04, Felipe Monteiro de Carvalho het geskryf:

In the standard Apache setup it will thread anything you put in the cgi-bin directory regardless of the extension as a cgi program. The path to this is set in httpd.conf here:

Thanks for the tip. Unfortunately I can't use the usual cgi-bin for my CGI apps, due to loading of external files as a requirement. Some of our served content is flash which also loads external shared resources - the later is the major obstacle with the usual cgi-bin directory.

Either way, I'll take a look in the Apache configs to see if I could reproduce the cgi-bin behaviour in another directory.

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://opensoft.homeip.net/fpgui/

Reply by email