Forum Moderators: phranque

Message Too Old, No Replies

Complicated Rewrite Help

Perhaps not best suited for mod rewrite

         

redijedi

10:52 pm on Sep 22, 2005 (gmt 0)



I'm not sure if this is possible, but given the power of Apache I hope it is.

I need to apply a rule based on a url path. All urls that begin with /special/(rest of path) must attempt to serve content from a specfic directory. This I have setup and working.

The first hard part is that if the file at the path does not exist, redirect to a different server within the network. This part I cannot get to work.

The second hard part, and maybe the hardest, is that the url in the address bar of the browser must remain the same as typed in.

I've RTFM'd all day, and though certain techniques seem to address certain parts of my problem, I cannot figure out how to complete the solution. Any help is GREATLY appreciated.

This is what I'm currently attempting:


Alias /special/ "C:/offer/pages/"
<Directory "C:/offer/pages/">
AllowOverride None
Order allow,deny
Allow from all
</Directory>


RewriteEngine on
RewriteCond /special/([^\/]+/.*)!-d
RewriteCond /special/([^\/]+/.*)!-f
RewriteRule ^/special/([^\/]+/.*)$ http://localhost:8080/offerengine/special/$1

It only does part one.

Thanks in advance,
Todd

jdMorgan

1:11 am on Sep 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



redijedi,

Welcome to WebmasterWorld!

Your RewriteCond syntax is 'misimplemented'... :)
You can't put regex in the left-hand side, and besides, what is that regex supposed to match against? (Rhetorical)

Some variation on the following should work:


EewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/special/([^\/]+/.*)$ http://localhost:8080/offerengine/special/$1 [P,L]

Sometimes, it's necesary to add the document root to the path for file- and directory- exists checks:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d

Jim

redijedi

1:58 am on Sep 23, 2005 (gmt 0)



Wow! Apache is powerful. Thanks for responding so quickly.

This looks like it's working for the most part. I'm getting a 403 Forbidden Error, however. If I remove the [P,L] it works, but then the url in the address bar gets rewritten. Is there any way around this?

Thanks again!

jdMorgan

2:05 am on Sep 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I'm getting a 403 Forbidden Error

Look at the access and error logs and at the access-control code on both servers to find out why you're getting the 403. Otherwise, I can only guess -- not a good use of my time or yours.

Jim

redijedi

2:57 am on Sep 23, 2005 (gmt 0)



The access log pretty much verifies that I'm getting a 403. The error log says:

[Thu Sep 22 19:25:28 2005] [warn] proxy: No protocol handler was valid for the URL /special/gotrlb/allyreu/. If you are using a DSO version of mod_proxy, make sure the proxy submodules are included in the configuration using LoadModule.

So I loaded each proxy module and it works now, kinda. Every request that matches the regex, regardless of whether the file exists or not, is being redirected through the proxy.

My config is now:


Alias /special/ "C:/offer/pages/"
<Directory "C:/offer/pages/">
Options Indexes FollowSymLinks MultiViews IncludesNoExec
AllowOverride None
Order allow,deny
Allow from all
</Directory>


RewriteEngine on
RewriteLog /rewrite.log
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^/special/([^\/]+/.*)$ http://localhost:8080/offerengine/special/$1 [P,L]


#
# Proxy Server directives. Uncomment the following lines to
# enable the proxy server:
#
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_connect_module modules/mod_proxy_connect.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_ftp_module modules/mod_proxy_ftp.so
<IfModule mod_proxy.c>
ProxyRequests On


<Proxy *>
Order deny,allow
Deny from all
Allow from all
</Proxy>


# Enable/disable the handling of HTTP/1.1 "Via:" headers.
# ("Full" adds the server version; "Block" removes all outgoing Via: headers)
# Set to one of: Off ¦ On ¦ Full ¦ Block
#
#ProxyVia Full


#
# To enable the cache as well, edit and uncomment the following lines:
# (no cacheing without CacheRoot)
#
#CacheRoot "C:/Program Files/Apache Group/Apache2/proxy"
#CacheSize 5
#CacheGcInterval 4
#CacheMaxExpire 24
#CacheLastModifiedFactor 0.1
#CacheDefaultExpire 1
#NoCache a-domain.com another-domain.edu joes.garage-sale.com


</IfModule>

Does anything seem to be missing?

Thanks again!