website URL catchall

Added by Mark Petryk about 5 years ago

How do I create a URL catchall?

http://www.mysite.com/jackdaniels
http://www.mysite.com/jimmydean
http://www.mysite.com/elvispresley
http://www.mysite.com/joeschmoe

Do I need to make a

server.addEntryPoint( Wt::Application, createApplication, "/jackdaniels", "images/img/favicon.ico" );

for each and every sub-path?

What I want is;

server.addEntryPoint( Wt::Application, createApplication, "",             "images/img/favicon.ico" ); // main site
server.addEntryPoint( Wt::Application, createApplication, "/admin", "images/img/favicon.ico" ); // back-end maintenance
server.addEntryPoint( Wt::Application, createApplication, "/jackdaniels", "images/img/favicon.ico" ); // client special site
server.addEntryPoint( Wt::Application, createApplication, "/jimmydean", "images/img/favicon.ico" ); // client special site
server.addEntryPoint( Wt::Application, createApplication, "/*", "images/img/favicon.ico" ); // catchall for everyone else

What I get if the entry point doesn't exist is simply a;

404 Not Found

I'd like a redirect page, basically.

~mark


Replies (9)

RE: website URL catchall - Added by Zalu Hobgobicus about 5 years ago

I used to just use:

server.addEntryPoint(Wt::Application, createApplication);

But I just updated Wt (3.3.0 to 3.3.4) and Ubuntu and other libraries, and now I'm not able to get to my running Wt app, so I am thinking Wt may need some new config settings or to re-read the docs, which I'm about to do...

RE: website URL catchall - Added by Mark Petryk about 5 years ago

Hi Zalu,

That's what I'm wondering if that's what's required - in other words, do I have to load an 'addEntryPoint' for each one of my 'subpages'...

The reason I'm asking is because these are affiliate 'redirect' pages. They really don't exist as pages themselves, they're just pages that someone can publish, and when followed, they actually end up being redirected to another location. An 'error' page is suitable for this;

For instance, if I have;

www.MySite.com/joejim         redirect ----> www.MySite.com/affiliate?code=joejim
www.MySite.com/alancox redirect ----> www.MySite.com/affiliate?code=alancox
www.MySite.com/fixyourpipes redirect ----> www.MySite.com/affiliate?code=fixyourpipes

I have about 200 of these guys. Each one gets their 'own' page, if you will, but it's just a redirect page anyhow. We don't want our affiliates handing out "MySite.com/affiliate?code=joejim" that looks awful. So, we install a simple URL page that they can easily publish and hand out to their customer lists. Looks cleaner in an email or on a business card.

But if I have 200+ redirects like this, do I have to install 'addEntryPoint' for each one of them? No problem if so, I was just wondering if there was a different method.

Thanks,

~mark

RE: website URL catchall - Added by Zalu Hobgobicus about 5 years ago

I see. I don't know, but I imagine that could be handled by one page, by responding to contents of the WEnvironment parameter to the your session class' constructor. But I'm not sure what it takes to catch all non-entry-point addresses, as I'm currently having trouble catching any. :-)

RE: website URL catchall - Added by Mark Petryk about 5 years ago

I may be fussing over nothing. If I open a database and redirect in an error handler, or pre-load my site with 'addEntryPoint' is probably doesn't matter. In the end the result would be the same.

Post your code maybe I can help.

RE: website URL catchall - Added by Zalu Hobgobicus about 5 years ago

Ok, yeah those don't sound like bad workarounds, though it would be good to know the syntax for handling a catchall.

I'll post my issue in the help forum here in a minute. Thanks.

RE: website URL catchall - Added by Yasin Yilmaz over 3 years ago

Once I need a web server to reply all pages directed by a spoofed DNS query.
I did it with two methods both worked just fine:
1- First:
I modified the wt source code as:
- in src/http/RequestHandler.C file
- in func bool RequestHandler::matchesPath(const std::string &path,const std::string &prefix,bool matchAfterSlash)
last return must be replaced by:
return( !( boost::starts_with(path,"/resources")));
So every request returns true and directed to my only entry point in wt application. There I handle the request by request URL and display correct content.

2- Second method:
I just replaces the `--errroot`/404-not-found.html file with a single line.
<meta http-equiv="refresh" content="0; url=http://MY_BIND_IP_ADDRESS" />
So every 404 situation is redirected to my entry point, where again I handle it according to my constraints like client ip address etc.

Both method works. First one is best but it is a headache to compile wt for an embedded device ... so second method is my choice at the moment.

Yasin

RE: website URL catchall - Added by Andrey Rusanov 8 months ago

so, is there more user-friendly way to handle full url now?

RE: website URL catchall - Added by Koen Deforche 7 months ago

Hey,

The solution I would propose is to deploy the app at "/" of your server, and indicate in the docroot all static resources resources (--docroot='/docroot;/css,/resources ...').

Then everything that does not match a static resources will be available as an internal path in your application.

In that way the redirect is not necessary either.

Regards,
koen

RE: website URL catchall - Added by Roel Standaert 7 months ago

Apart from that, Wt 4 can also do parametrized paths since Wt 4.0.4. You just use /${foo} as the path, which will match with lowest priority, and you can get its value using urlParam() https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1Http_1_1Request.html#a56f41f5df0dc8cc160c313fea44d1c1c in a WResource. I think it should also work for Application entry points, but I think there's no urlParam() in WEnvironment at the moment.

(1-9/9)