logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: How can I keep the URL unchanged after redirecting
Author
chenyichen



Joined: 20 Sep 2012
Posts: 3
Location: Taiwan (R.O.C.), Taipei City

PostPosted: Fri 19 Oct '12 3:30    Post subject: How can I keep the URL unchanged after redirecting Reply with quote

Dear Sir,

There is one issue needing to consult:

I have set up Apache as a SSL front end for our web applications deployed in GlassFish Server 3.0.1 Open Source Edition, how can I keep the original URL displayed in the web browser address bar unchanged after redirecting via Rewrite / ProxyPass and ProxyPassReverse Question

Best Regards and Have a Nice Day

Chen Yi Chen

Reference 1:
RewriteEngine On

# If the request URL does not start with a slash (/), prepend it.
RewriteRule ^([^/].*)$ /$1 [E=redirect:y,N]
# If the request URL starts with more than one slash (/), keep only the first one.
RewriteRule ^//+(.*)$ /$1 [E=redirect:y,N]
# If there are more than one dot (.) in succession in the URL, replace them with just one.
RewriteRule ^(.*)\.\.+(.*)$ $1.$2 [E=redirect:y,N]
# If there are more than one slash (/) in succession in the URL, replace them with just one.
RewriteRule ^(.*)//+(.*)$ $1/$2 [E=redirect:y,N]
# Replace any ./ in the URL with just /
RewriteRule ^(.*)\./(.*)$ $1/$2 [E=redirect:y,N]
# Replace any /. in the URL with just /
RewriteRule ^(.*)/\.(.*)$ $1/$2 [E=redirect:y,N]
# If the last component in the URL is non-empty but does not contain a dot, append a slash /
RewriteRule ^(.*/[^/.]+)$ $1/ [E=redirect:y,N]
# If any of the above rules were applied, they set the environment variable redirect to y (and restart the entire chain all over again). When they reach this point, all replacements possible have already been made.
# If and only if there were any substitutions made, the environment variable will have a y in it. If so, apply the following RewriteRule.
RewriteCond %{ENV:redirect} y
# Use a single visible redirect to redirect the browser to the cleaned up URL right now.
RewriteRule ^(.*)$ $1 [R,L]

RewriteRule ^/glassfish/(.*) http://localhost:4848/common/$1 [P]
RewriteRule ^/pcmm/(.*) http://semopstest.com:8380/pcmm$1 [P]
RewriteRule (.*) https://semopstest.com:8181$1 [P]
ProxyPassReverse /glassfish/ http://localhost:4848/common/
ProxyPassReverse /pcmm/ http://semopstest.com:8380/pcmm/
ProxyPassReverse / https://semopstest.com:8181/

# ProxyPass /glassfish/ http://localhost:4848/common/
# ProxyPass /pcmm/ http://semopstest.com:8380/pcmm
# ProxyPass / https://semopstest.com:8181/
# ProxyPassReverse /glassfish/ http://localhost:4848/common/
# ProxyPassReverse /pcmm/ http://semopstest.com:8380/pcmm
# ProxyPassReverse / https://semopstest.com:8181/
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Mon 22 Oct '12 11:21    Post subject: Reply with quote

You should use a reverse proxy instead of rewriting. And if you can use ajp instead of http protocol. for my jenkins I use this setup with mod_proxy_ajp

Code:

<VirtualHost *:80>
    ServerName jenkins
    DocumentRoot "/mario/Apache22/htdocs"
    <Directory "/mario/Apache22/htdocs">
        Options Indexes Includes FollowSymLinks
        AllowOverride All
        Order Allow,Deny
        Allow from all
        Deny from none
    </Directory>
    <Location />
        ProxyPass ajp://localhost:8009/
        ProxyPassReverse ajp://localhost:8009/
    </Location>
</virtualhost>


Than start the backend server, in this case only with AJP and listen only on localhost (I don't know if that works for glassfish, too this way.

Code:

java -jar jenkins.war --httpPort=-1 --ajp13ListenAddress=127.0.0.1
Back to top
chenyichen



Joined: 20 Sep 2012
Posts: 3
Location: Taiwan (R.O.C.), Taipei City

PostPosted: Wed 24 Oct '12 5:00    Post subject: Re: How can I keep the URL unchanged after redirecting Reply with quote

Dear James Blond,

Did you mean that I can keep the original URL displayed in the web browser address bar unchanged after using ProxyPass instead of RewriteRule and using ajp instead of http protocol Question

Best Regards and Have a Nice Day

Chen Yi Chen
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7355
Location: Germany, Next to Hamburg

PostPosted: Wed 24 Oct '12 12:10    Post subject: Re: How can I keep the URL unchanged after redirecting Reply with quote

chenyichen wrote:

Did you mean that I can keep the original URL displayed in the web browser address bar unchanged after using ProxyPass instead of RewriteRule


Yey you can keep the URL that way.
chenyichen wrote:

and using ajp instead of http protocol Question


using ajp is a "can" not a "must". I just noticed that than there are no path issues with pictures and stuff if they are not set with relative paths. Also ajp work bidirectional and keeps the connection alive not like http which is fire and forget.

I wonder a bit, since you already had the ProxyPass and ProxyPassReverse stuff below your config, but commented out.
Back to top
chenyichen



Joined: 20 Sep 2012
Posts: 3
Location: Taiwan (R.O.C.), Taipei City

PostPosted: Thu 25 Oct '12 11:00    Post subject: Re: Re: How can I keep the URL unchanged after redirecting Reply with quote

Dear James Blond,

I suppose that I should re-describe so-called "keep the original URL displayed in the web browser address bar unchanged" issue below.

While I access the https://semopstest.com/ , the Rewrite / ProxyPass and ProxyPassReverse mechanism will forward my request to https://semopstest.com:8181/ .

Here https://semopstest.com/ is the original URL displayed in the web browser address bar; besides, I have the https://semopstest.com/web/guest%3bjsessionid=6e2cce81d8700b675aa53f96c4ac/ URL displayed in the web browser address bar after redirecting via Rewrite / ProxyPass and ProxyPassReverse.

Did you mean that I can keep the https://semopstest.com/web/guest%3bjsessionid=6e2cce81d8700b675aa53f96c4ac/ URL as https://semopstest.com/ after using ProxyPass instead of RewriteRule and using ajp instead of http protocol Question

Best Regards and Have a Nice Day

Chen Yi Chen
Back to top


Reply to topic   Topic: How can I keep the URL unchanged after redirecting View previous topic :: View next topic
Post new topic   Forum Index -> Apache