Certary
Certary

Reputation: 37

Is it possible to prevent redirecting / to /welcome-file when using OmniFaces ExtensionlessURLs

I'm using JSF 2.2 and OmniFaces ExtensionlessURLs to remove the file extensions from my URLs: www.exmaple.com/appname/login.xhtml -> .../appname/login. Now when I navigate to www.example.com/appname/ I always get forwarded to www.exmaple.com/appname/login. Is it possible to prevent this redirect and to instead serve login.xhtml from www.example.com/appname/?

My .xhtml-files are stored in /WebContent/html/.

Relevant details from my web.xml:

<welcome-file-list>
   <welcome-file>login.xhtml</welcome-file>
</welcome-file-list>

<servlet>
   <servlet-name>Faces Servlet</servlet-name>
   <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
   <load-on-startup>-1</load-on-startup>
   <enabled>true</enabled>
   <async-supported>false</async-supported>
</servlet>
<servlet-mapping>
   <servlet-name>Faces Servlet</servlet-name>
   <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<context-param>
   <param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
   <param-value>/html/*.xhtml</param-value>
</context-param>

Upvotes: 1

Views: 238

Answers (1)

BalusC
BalusC

Reputation: 1109292

From the showcase:

Advanced configuration

See package documentation for configuration settings as to mapping, filtering and forwarding behavior.

From the package documentation:

Welcome files

If a <welcome-file> is defined in web.xml that's scanned by FacesViews AND REDIRECT_TO_EXTENSIONLESS is used (which is the default, see below), it's necessary to define an extensionless welcome file to prevent a request to / being redirected to /[welcome file]. E.g. without this http://example.com will redirect to say http://example.com/index.

For example:

<welcome-file-list>
    <welcome-file>index</welcome-file>
</welcome-file-list>

In other words, edit your welcome file to say login instead of login.xhtml.


Unrelated to the concrete problem: note though that you seem to have a general misunderstanding of the exact meaning of a "welcome file", because it's a bit strange that you could possibly have a login.xhtml file in every single folder. See also Set default home page via <welcome-file> in JSF project

Upvotes: 2

Related Questions