Rewrite + proxy + POST answers with 302?

Discuss practical ways rearrange URLs using mod_rewrite.

Rewrite + proxy + POST answers with 302?

Postby hu2hugo » Fri May 22, 2009 6:45 am

The virtual host below forwards all traffic to a web app except for some special addresses. This generally works including GET requests that are passed to the web app. However, when I send a POST request to the web app, apache sends a 302 to the same address according to the log.

For testing purposes, the weba app (=internal01.net) resolves to 127.0.0.1 . Is this the problem?

Thanks for any hints,
Hugo


<VirtualHost *:443>
RewriteEngine on

## Rewrite logging is just for debugging
#RewriteLog /var/log/apache2/rewrite_log
#RewriteLogLevel 5

RewriteCond %{HTTP_HOST} ^(.+)\.example\.net
RewriteRule ^/$ http://internal01.net:8080/global/applaunch?cid=%1 [qsappend,proxy,last]

RewriteCond %{HTTP_HOST} ^(.+)\.example\.net
RewriteRule ^/global/(.*) http://internal01.net:8080/global/$1?cid=%1 [qsappend,proxy,last]

RewriteCond /var/www%{REQUEST_FILENAME} -f
RewriteRule ^(.*) $1 [last]

RewriteRule ^/static/(.*) /static/$1 [last]

# THIS RULE SEEMS TO WORK ONLY FOR GET REQUESTS:
RewriteRule ^/(.*) http://internal01.net:8080/$1 [proxy,last]

SSLEngine on
SSLCertificateFile .....crt
SSLCertificateKeyFile ......key
SSLCertificateChainFile ......crt
</VirtualHost>
hu2hugo
 
Posts: 2
Joined: Fri May 22, 2009 6:14 am

Postby richardk » Fri May 22, 2009 8:04 am

However, when I send a POST request to the web app, apache sends a 302 to the same address according to the log.

Does the browser get redirected?

For testing purposes, the weba app (=internal01.net) resolves to 127.0.0.1 . Is this the problem?

If you don't proxy the request and just POST to internal01.net do you still get redirected?

Code: Select all
<VirtualHost *:443>
  RewriteEngine On

  ## Rewrite logging is just for debugging
  #RewriteLog /var/log/apache2/rewrite_log
  #RewriteLogLevel 5

  RewriteCond %{HTTP_HOST} ^(.+)\.example\.net
  RewriteRule ^/$ http://internal01.net:8080/global/applaunch?cid=%1 [QSA,P,L]

  RewriteCond %{HTTP_HOST} ^(.+)\.example\.net
  RewriteRule ^/global/(.*) http://internal01.net:8080/global/$1?cid=%1 [QSA,P,L]

  RewriteCond /var/www%{REQUEST_FILENAME} -f
  RewriteRule . - [L]

  RewriteRule ^/static(/.*)?$ - [L]

  RewriteRule ^(/.*)$ http://internal01.net:8080$1 [P,L]

  SSLEngine On
  SSLCertificateFile      .....crt
  SSLCertificateKeyFile   ......key
  SSLCertificateChainFile ......crt
</VirtualHost>
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby hu2hugo » Fri May 22, 2009 12:25 pm

Thanks for the improvements in the code, I appreciate.

richardk wrote:
However, when I send a POST request to the web app, apache sends a 302 to the same address according to the log.

Does the browser get redirected?

Yes, apache replies with a HTTP Status 302. I checked this also with Wireshark (that had the server key provided).


For testing purposes, the weba app (=internal01.net) resolves to 127.0.0.1 . Is this the problem?

If you don't proxy the request and just POST to internal01.net do you still get redirected?


No, the web app does not send the 302. I first validated this with logs and debug mode in the app. Because you asked, I also connected now directly to the app and the web app definitely does not send the redirect.

I've just tried the configuration below. I moved to port 80 and removed the SSL encryption. This works fine!

Thanks for any suggestion,
Hugo



<VirtualHost *:80>
RewriteEngine On

RewriteCond %{HTTP_HOST} ^(.+)\.example\.net
RewriteRule ^/$ http://internal01.net:8080/global/applaunch?cid=%1 [QSA,P,L]

RewriteCond %{HTTP_HOST} ^(.+)\.example\.net
RewriteRule ^/global/(.*) http://internal01.net:8080/global/$1?cid=%1 [QSA,P,L]

RewriteCond /var/www%{REQUEST_FILENAME} -f
RewriteRule . - [L]

RewriteRule ^/static(/.*)?$ - [L]

RewriteRule ^(/.*)$ http://internal01.net:8080$1 [P,L]
</VirtualHost>
hu2hugo
 
Posts: 2
Joined: Fri May 22, 2009 6:14 am

Postby richardk » Sat May 23, 2009 4:02 pm

I have no idea why it would do that.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 19 guests

cron