URL Rewriting
Added by Yasin Yilmaz almost 9 years ago
Hello,
I am new to Wt.
I would like to know how can I rewrite url path in wt server?
Such as changing
http://localhost/xyz -> http://localhost/
Any example code is highly appreciated.
Thanks
Yasin
Replies (2)
RE: URL Rewriting - Added by Yasin Yilmaz almost 9 years ago
In file WebController.C from Wt sourcecode, entry points are selected by code:
bool matchesPath(const std::string& path, const std::string& prefix)
{
if (boost::starts_with(path, prefix)) {
unsigned prefixLength = prefix.length();
if (path.length() > prefixLength) {
char next = path[prefixLength];
if (next == '/')
return true;
}
else
return true;
}
return false;
}
}
which implies that
http://localhost/asdfdd is not redirected to http://localhost/ (WHICH IS WHAT I WANT)
but
http://localhost//asdfdd IS redirected to http://localhost/
Is this an intended behaviour.
RE: URL Rewriting - Added by Yasin Yilmaz almost 9 years ago
changing the code in requesthandler.C as follows fixed my issue.
ps. This is a bad solution for a specific case, but it is a solution until I got some support from the experts :)
//Resources are always in /resources folder.
bool RequestHandler::matchesPath(const std::string &path,const std::string &prefix,bool matchAfterSlash)
{
if (boost::starts_with(path,prefix))
{
unsigned prefixLength = prefix.length();
if (path.length() > prefixLength)
{
char next = path[prefixLength];
if (next \'/\')
{
return( true );
}
else if (matchAfterSlash)
{
char last = prefix[prefixLength - 1];
if (last '/')
{
return( true );
}
}
}
else
{
return( true );
}
}
return( !( boost::starts_with(path,"/resources")));
}