Forum

Slashes instead of URL parameters result in a 404 error

Slapo
25 December 2012, 21:05
Hiawatha version: 8.6
Operating System: Windows 7 x64 Professional

Good day,

I'm trying out Hiawatha (on Windows, as it's what I use for development) and I've run into a bit of an issue when trying to use e. g.
http://localhost/index.php/id=1

instead of
http://localhost/index.php?id=1

If I use
index.php/id=1
, I get a 404 error. It looks like Hiawatha is looking for a directory in this case.
Is there a way to work around this? I've tried a rewrite, but it seems rewrite toolkits (along with the ShowIndex directive) are ignored for the default website. When I had a toolking rewrite index.php/id=1 to index.php?id=1 (rewrite rules should have worked, as they seemed to work with wigwam), I still got a 404.

Here's my hiawatha.conf:

# Hiawatha main configuration file
#


# GENERAL SETTINGS
#
#ServerId = www-data
ConnectionsTotal = 150
ConnectionsPerIP = 10
SystemLogfile = D:\programy\apps\web_servers\hiawatha\log\system.log
GarbageLogfile = D:\programy\apps\web_servers\hiawatha\log\garbage.log

## Cache and compression settings
CacheSize = 15
UseGZfile = yes

## Security settings
## PreventCSRF = yes
## PreventXSS = yes

# BINDING SETTINGS
# A binding is where a client can connect to.
#
Binding {
Port = 80
Interface = 127.0.0.1
MaxKeepAlive = 30
TimeForRequest = 3,20
}
#
#Binding {
# Port = 443
# Interface = ::1
# MaxKeepAlive = 30
# TimeForRequest = 3,20
# SSLcertFile = D:\programy\apps\web_servers\hiawatha\config\hiawatha.pem
#}


# BANNING SETTINGS
# Deny service to clients who misbehave.
#
#BanOnGarbage = 300
#BanOnMaxPerIP = 60
#BanOnMaxReqSize = 300
#KickOnBan = yes
#RebanDuringBan = yes


# COMMON GATEWAY INTERFACE (CGI) SETTINGS
# These settings can be used to run CGI applications. Use the 'php-fcgi'
# tool to start PHP as a FastCGI daemon.
#
#CGIhandler = D:\programy\apps\interpreters\php_5.4\php-cgi.exe:php
#CGIhandler = D:\programy\apps\web_servers\hiawatha\bin\ssi-cgi.exe:shtml
#CGIextension = php
#
FastCGIserver {
FastCGIid = PHP5
ConnectTo = 127.0.0.1:9000
Extension = php
}


# URL TOOLKIT
# This URL toolkit rule was made for the Banshee PHP framework, which
# can be downloaded from http://www.hiawatha-webserver.org/banshee
#
UrlToolkit {
ToolkitID = slapo
Match /(.*\.php)(.*) Rewrite /$1$2
Match /(\?|main/)(.*) Rewrite /index.php?$2
RequestURI exists Return
}
UrlToolkit {
ToolkitID = yii
RequestURI exists Return
Match /.* Rewrite /index.php
}


# DEFAULT WEBSITE
# It is wise to use your IP address as the hostname of the default website
# and give it a blank webpage. By doing so, automated webscanners won't find
# your possible vulnerable website.
#
Hostname = 127.0.0.1, localhost
WebsiteRoot = F:/dokumenty/weby
StartFile = index.html
AccessLogfile = D:\programy\apps\web_servers\hiawatha\log\access.log
ErrorLogfile = D:\programy\apps\web_servers\hiawatha\log\error.log
ShowIndex = no
MaxRequestSize = 32768
MaxUploadSize = 32
TimeForCGI = 10
UseFastCGI = PHP5
UseToolkit = slapo
NoExtensionAs = php


Thanks in advance.
Hugo Leisink
25 December 2012, 22:18
You can solve this is issue with "EnablePathInfo = yes".

However, my advice is to not write an application which requires the PathInfo option. It is a deprecated technique. Instead, use an URL rewrite rule that rewrites all requests for non-existing files to /index.php:
UrlToolkit {
ToolkitID = generic
RequestURI isfile Return
Match .* Rewrite /index.php
}


You can now use URLs like http://localhost/page/1, which is much more user friendly. The index.php script can perform actions, like including other PHP scripts, based in the original URL which can be found in $_SERVER["REQUEST_URI"].
Slapo
26 December 2012, 10:26
Thanks for the response. I've tried both of your suggestions but it seems the default website still ignores both the toolkit I set and the EnablePathInfo directive.
Have I missed something in the documentation and are they really valid only in virtual host sections?

# Hiawatha main configuration file
#

# GENERAL SETTINGS
#
ConnectionsTotal = 150
ConnectionsPerIP = 10
SystemLogfile = D:\programy\apps\web_servers\hiawatha\log\system.log
GarbageLogfile = D:\programy\apps\web_servers\hiawatha\log\garbage.log

## Cache and compression settings
CacheSize = 15
UseGZfile = yes

# A binding is where a client can connect to.
#
Binding {
Port = 80
Interface = 127.0.0.1
MaxKeepAlive = 30
TimeForRequest = 3,20
}

# COMMON GATEWAY INTERFACE (CGI) SETTINGS
# These settings can be used to run CGI applications. Use the 'php-fcgi'
# tool to start PHP as a FastCGI daemon.
#
FastCGIserver {
FastCGIid = PHP5
ConnectTo = 127.0.0.1:9000
Extension = php
}

UrlToolkit {
ToolkitID = generic
RequestURI isfile Return
Match .* Rewrite /index.php
}


# DEFAULT WEBSITE
#
Hostname = 127.0.0.1, localhost
WebsiteRoot = F:/dokumenty/weby
StartFile = index.html
AccessLogfile = D:\programy\apps\web_servers\hiawatha\log\access.log
ErrorLogfile = D:\programy\apps\web_servers\hiawatha\log\error.log
ShowIndex = no
MaxRequestSize = 32768
MaxUploadSize = 32
TimeForCGI = 10
UseFastCGI = PHP5
UseToolkit = generic
NoExtensionAs = php
EnablePathInfo = yes
Hugo Leisink
26 December 2012, 10:29
You should chose one of the options. Use EnablePathInfo = yes, which enables the usage of URLs like http://localhost/index.php/stuff. OR... use the rewrite rule I provided, which enables the usage of URLs like http://localhost/stuff.
Slapo
26 December 2012, 14:43
I've just tried it with only the rewrite rule and and with only the EnablePathInfo = yes directive, but in neither case has this worked and I still got a 404.
Could this have something in common with the "ShowIndex = no" being ignored?

Thanks. :-)
Hugo Leisink
26 December 2012, 14:47
Did you write the PHP application yourself or is it something you downloaded from the internet? If so, what application is it and from what website did you download it from?
Slapo
26 December 2012, 16:19
It's mine. After trying the same thing with Apache 2.4, I got the "No input specified" error, so I realised it's probably something in my PHP configuration.
I've spotted I've turned cgi.fix_pathinfo off as instructed here:
https://www.hiawatha-webserver.org/howto/php_configuration
Turning it on fixed the issue when running it with Apache.
However, the result is still the same with Hiawatha - a 404 error. It's quite puzzling for me.
Hugo Leisink
26 December 2012, 17:51
I have no idea what you are doing. All I can say is that the EnablePathInfo option works and that URL rewriting works. I use the last one every day.
Slapo
26 December 2012, 21:53
I'll try to work at it for a bit longer. Thanks for the help so far. :-)
This topic has been closed.