Configuring redirects in undertow-handlers.conf for Wildfly server

Hi all,

I have been searching for a while online but not sure if it’s I’m too new to the topic or there is actually not a lot of documentation on it out there. Whichever the case I’d appreciate your help or guidance…

What I’m trying to do is the classic redirect all requests to index.html with the exception of asset files. What we do in Apache with the following code in the .htaccess file:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

I have something like this in my undertow-handlers.conf, which obviously does not work as expected but almost there:

regex['/[^\/]+\/.*'] -> rewrite['/index.html']

Was trying to find documentation on how to write a rewrite conditional for the asset files.
All I could find is this article:

At the bottom there are 2 suggestions:

not file(%U) -> redirect('/index.html')


not equals[%R, '/'] and
not equals[%R, '/index.html'] and
regex['/.+'] -> rewrite['/km/index.html']

but none of them have worked for me…

Thanks again

Try this:

If it works ok and the assets directory contains files used in index.html, I think they will be blocked if a URL is being used.

I think this problem can be overcome by using paths instead of URLs.

1 Like

Thanks @John_Betong, the problem is however not with Apache… but with Wildfly server, which completely new to me…

ok so I have got it working temporarily by merely adding a regex with a list of extensions for files to ignore. Not ideal because we will have to keep adding to the list but it does work well for our purposes for the time being:

regex['.*[^(.js)(.svg)]$'] -> rewrite['/index.html']
1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.