-
1. Re: Redirect URL using Rewrite value
jfclere Nov 6, 2013 5:34 AM (in response to nc12_5446)Try with just:
RewriteRule ^/$ /app/index.html [L]
-
2. Re: Redirect URL using Rewrite value
nc12_5446 Nov 6, 2013 9:03 AM (in response to jfclere)Thank you for folllowng up Jean-Frederic
I have added just the ReWriteRule you provided and its still not working. When I enter https://hostname.net I get routed to the JBoss web console and not to https://hostname.net/app.index.html. I also tried adding the ReWriteCond back to the properties file as well but it didn't help either.
ReWriteCond %{REQUEST_URI}
ReWriteRule ^/$ /app/index.html [L]
Any further suggestions or whats the best way to debug whats going on?
Thanks Again!
-
3. Re: Redirect URL using Rewrite value
jfclere Nov 6, 2013 11:57 AM (in response to nc12_5446)"JBoss web console" weird I would have except the JBossWeb main index page.
Try with
ReWriteRule ^/$ https://hostname.net/app/index.html [R,L]
that should do a browser redirect, if not the rewrite.properties is not at the right place... Why in localhost subdirectory?
You try to debug via:
+++
<category name="org.jboss.web">
<priority value="DEBUG"/>
</category>
+++And look in server/default/log/server.log (I am using default)
-
4. Re: Redirect URL using Rewrite value
nc12_5446 Nov 6, 2013 12:45 PM (in response to jfclere)I should be more specific and say that it takes me to the JBoss Management console, where you can see links to Tomcat, Jboss Web Console and JMX console.
Perhaps the location of the file is incorrect then. I only placed the rewrite.properties in this local because I found a post somewhere explaining this is where it should go. I had to manully create the $JBOSS_HOME\default\conf\jboss.web\localhost directories as they didn't exist.
Where should the rewrite.properties file go then? Here is a excerpt from the server.xml where I placed the <Valve className="org.jboss.web.rewrite.RewriteValve" />
.........
<Engine name="jboss.web" defaultHost="localhost">
- <!-- The JAAS based authentication and authorization realm implementation
that is compatible with the jboss 3.2.x realm implementation.
- certificatePrincipal : the class name of the
org.jboss.security.auth.certs.CertificatePrincipal impl
used for mapping X509[] cert chains to a Princpal.
- allRolesMode : how to handle an auth-constraint with a role-name=*,
one of strict, authOnly, strictAuthOnly
+ strict = Use the strict servlet spec interpretation which requires
that the user have one of the web-app/security-role/role-name
+ authOnly = Allow any authenticated user
+ strictAuthOnly = Allow any authenticated user only if there are no
web-app/security-roles
-->
<Realm className="org.jboss.web.tomcat.security.JBossSecurityMgrRealm" certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping" allRolesMode="authOnly" />
- <!-- A subclass of JBossSecurityMgrRealm that uses the authentication
behavior of JBossSecurityMgrRealm, but overrides the authorization
checks to use JACC permissions with the current java.security.Policy
to determine authorized access.
- allRolesMode : how to handle an auth-constraint with a role-name=*,
one of strict, authOnly, strictAuthOnly
+ strict = Use the strict servlet spec interpretation which requires
that the user have one of the web-app/security-role/role-name
+ authOnly = Allow any authenticated user
+ strictAuthOnly = Allow any authenticated user only if there are no
web-app/security-roles
<Realm className="org.jboss.web.tomcat.security.JaccAuthorizationRealm"
certificatePrincipal="org.jboss.security.auth.certs.SubjectDNMapping"
allRolesMode="authOnly"
/>
-->
- <Host name="localhost" autoDeploy="false" deployOnStartup="false" deployXML="false" configClass="org.jboss.web.tomcat.security.config.JBossContextConfig">
- <!-- Uncomment to enable request dumper. This Valve "logs interesting
contents from the specified Request (before processing) and the
corresponding Response (after processing). It is especially useful
in debugging problems related to headers and cookies."
-->
- <!-- <Valve className="org.apache.catalina.valves.RequestDumperValve" />
-->
<Valve className="org.jboss.web.rewrite.RewriteValve" />
- <!-- Access logger
-->
<Valve className="org.apache.catalina.valves.AccessLogValve" prefix="localhost_access_log." suffix=".log" pattern="common" directory="${jboss.server.log.dir}" resolveHosts="false" />
- <!-- Uncomment to enable single sign-on across web apps
deployed to this host. Does not provide SSO across a cluster.
If this valve is used, do not use the JBoss ClusteredSingleSignOn
valve shown below.
A new configuration attribute is available beginning with
release 4.0.4:
cookieDomain configures the domain to which the SSO cookie
will be scoped (i.e. the set of hosts to
which the cookie will be presented). By default
the cookie is scoped to "/", meaning the host
that presented it. Set cookieDomain to a
wider domain (e.g. "xyz.com") to allow an SSO
to span more than one hostname.
-->
- <!-- <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
-->
- <!-- Uncomment to enable single sign-on across web apps
deployed to this host AND to all other hosts in the cluster.
If this valve is used, do not use the standard Tomcat SingleSignOn
valve shown above.
Valve uses a JBossCache instance to support SSO credential
caching and replication across the cluster. The JBossCache
instance must be configured separately. By default, the valve
shares a JBossCache with the service that supports HttpSession
replication. See the "jboss-web-cluster-service.xml" file in the
server/all/deploy directory for cache configuration details.
Besides the attributes supported by the standard Tomcat
SingleSignOn valve (see the Tomcat docs), this version also
supports the following attributes:
cookieDomain see above
treeCacheName JMX ObjectName of the JBossCache MBean used to
support credential caching and replication across
the cluster. If not set, the default value is
"jboss.cache:service=TomcatClusteringCache", the
standard ObjectName of the JBossCache MBean used
to support session replication.
-->
- <!-- <Valve className="org.jboss.web.tomcat.service.sso.ClusteredSingleSignOn" />
-->
- <!-- Check for unclosed connections and transaction terminated checks
in servlets/jsps.
Important: The dependency on the CachedConnectionManager
in META-INF/jboss-service.xml must be uncommented, too
-->
<Valve className="org.jboss.web.tomcat.service.jca.CachedConnectionValve" cachedConnectionManagerObjectName="jboss.jca:service=CachedConnectionManager" transactionManagerObjectName="jboss:service=TransactionManager" />
</Host>
</Engine>
</Service>
</Server>
-
5. Re: Redirect URL using Rewrite value
jfclere Nov 7, 2013 4:37 AM (in response to nc12_5446)with debug I have:
+++
2013-11-07 10:04:58,853 INFO [org.apache.catalina.core.ContainerBase] No configuration resource found: jboss.web/localhost/rewrite.properties in /home/jfclere/JBPAPP_4_2_0_GA_CP/build/output/jboss-4.3.0.GA_CP10/server/default/conf or in the classloader
+++I have created the file and put:
RewriteRule ^/$ https://hostname.net/app/index.html [R,L]
with curl I have:
+++
[jfclere@jfcpc jboss-4.3.0.GA_CP10]$ curl -v http://localhost:8080/
* About to connect() to localhost port 8080 (#0)
* Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> User-Agent: curl/7.29.0
> Host: localhost:8080
> Accept: */*
>
< HTTP/1.1 302 Moved Temporarily
< Server: Apache-Coyote/1.1
< Location: https://hostname.net/app/index.html
< Transfer-Encoding: chunked
< Date: Thu, 07 Nov 2013 09:34:16 GMT
<
* Connection #0 to host localhost left intact
+++So try with:
RewriteRule ^/$ /app/index.html [L]
-
6. Re: Redirect URL using Rewrite value
nc12_5446 Nov 8, 2013 12:59 PM (in response to jfclere)After I put the rewrite.properties file in the correct location, it worked like a charm.
thanks so much for your advice.
cheers
-
7. Re: Redirect URL using Rewrite value
gurushant Dec 24, 2013 1:05 AM (in response to jfclere)Hi Jean,
I am working on JBoss 5 and I am trying to redirect a static HTML page or restrict from accessing for any user but rewrite is not at all working for me.
I have added the <Valve className="org.jboss.web.rewrite.RewriteValve" /> under <Engine> element in server.xml file. now in rewrite.properties file i have added following line.
RewriteRule "^/$" http://google.com [R,L]
I have placed rewrite.properties file at \$JBOSS_HOME\server\<server_name>\conf\. This approach is not at all working for me. Even I have tried following re write rules,
1. RewriteRule "^/$" /abc.html [F] - (trying to restrict this HTML file from accessing)
2. RewriteRule "^/abc.html" http://google.com [R]
3. RewriteRule "^/abc.html" http://google.com
4. ReWriteCond %{REQUEST_URI}
RewriteRule "^/$" /abc.html [R,L]
None of above Rule is working for me.
Please correct me if I am doing something wrong here. Redirect to some page or restrict to access that page will work for me.
-
8. Re: Redirect URL using Rewrite value
jfclere Dec 31, 2013 4:24 AM (in response to gurushant)You need to put the file in the right location for the Engine:
./server/<server_name>/conf/jboss.web/rewrite.properties
for a Host (for localhost for example):
./server/<server_name>/conf/jboss.web/localhost/rewrite.properties
-
9. Re: Redirect URL using Rewrite value
gurushant Dec 31, 2013 8:46 AM (in response to jfclere)Hey Thank you Jean,
The fix you provided had worked for me. I had to create jboss.web folder and place my rewrite.properties file in it and now rewrite is working properly.
However, I am trying to redirect a URL which like "http://<server_IP>/app?service=asset&path=abc/xyz-0.4.1/filt.html" to some other URL or other website. But I am facing lot of problem to redirect only this URL or a URL ending with "file.html".
Could you suggest what would be the proper Regex to match URL ends with "file.html"?
-
-
11. Re: Redirect URL using Rewrite value
gurushant Jan 3, 2014 4:49 AM (in response to jfclere)Thanks a lot Jean..!!!!!
That is the just a matter of using RewriteCond with %{QUERY_STRING}, which i was missing in my Rewrite.properties file to match URL. Your suggestions worked so accurate for me.
-
12. Re: Redirect URL using Rewrite value
gurushant Jan 9, 2014 4:38 AM (in response to jfclere)Hello Jean-Frederic Clere
Hey your instructions really worked a lot for me. Thank you again for it.
Now I am able to rewrite the URL and redirect it to other location. But, in my case as I want to restrict access to URL like "http://<server_IP>/app?service=asset&path=abc/xyz-0.4.1/file.html", So I used [F] forbidden flag to deny access to that URL. This worked absolutely fine for me, but the issue is that this will work only if user hit the above URL into browser. If the URL mentioned is got called as an internal request or while loading java script files, then in such cases JBoss Rewrite will not work as it shows me the content of the original page in response.
In my case if I hit login page, then the URL "http://<server_IP>/app?service=asset&path=abc/xyz-0.4.1/file.html" is getting called internally while loading some java script files. The content of file.html will not get displayed in this case but the response can bee seen using request tracking tools like "Fiddler or Developer Tools of IE".
My rewrite.properties file is as follows,
RewriteCond %{QUERY_STRING} ^service=asset&path=abc/xyz\-0\.4\.1/file\.html
RewriteRule ^/app(.*) /blank.html? [R]
This will work only If the URL is hit by browser but will not be redirected as expected when the URL is called internally while loading third party js files.
Do you have any idea about it?
-
13. Re: Redirect URL using Rewrite value
gurushant Jan 9, 2014 9:54 AM (in response to jfclere)Hello jfclere,
Sorry for troubling you. But I got the solution for above problem. It was the issue of case sensitive RewriteCond. Now Rewrite is working absolutely fine using [NC] flag as third parameter for RrwriteCond.
Thank you.
-
14. Re: Redirect URL using Rewrite value
gurushant Mar 18, 2014 7:50 AM (in response to jfclere)Hello Jean-Frederic Clere,
Thank you for the help.
I have used JBoss Rewrite successfully in my application and the URL getting redirected correctly as expected. But currently I am facing some problem with it when I run my application in IE version 9. I have added rewrite condition as follows,
RewriteCond %{QUERY_STRING} ^service=asset&path=abc/xyz\-0\.4\.1/file\.html
RewriteRule ^/app(.*) - [F]
To be more specific with issue, I am using dojo in my application for back button prevention and I am trying to restrict user to access a dojo page which is security vulnerable. The above rewrite condition is for the same reason to deny user to access dojo page and send a 403 response for this URl. This link is getting called internally while browsing to every page in my web application.
Now the problem is that the this fix works fine in all other browsers except IE version 9 and above. IE 9 is treating the dojo page url as as a separate request and adds it in history page (Only once as a previous page of current page. if user navigates to next page then again the previous page is added as dojo page). Thus when user clicks back button then the same page will be displayed.(as the dojo URl will receive responce as 403). User need to click BACK button twice to go back to previous page. The worst scenario is now when user has navigated to previous page, the forword button get disabled (may be because now the next URL will be a dojo URL)
Do you have any guidelines to avoid this problem?
Note:- For other browsers like Chrome and Firefox this issue is not present there.