Forum Moderators: phranque
RewriteEngine on
RewriteRule (.*\.asp) [192.168.0.102:81...] [P]
The problem, is that if the URL is [localhost...] and the default document is index.asp that gets loaded, the rule doesn't work, since "index.asp" isn't specifically in the URL.
I need the rules to work when the default document that has been loaded is *.asp, but not when it's *.php, or *.htm.
Ideas? Suggesstions? Help!
What determines "when the default document that [will be] loaded is *.asp, but not [...] *.php, or *.htm"?
RewriteRule sees only URLs, not filenames. If some other mechanism (such as DirectoryIndex) is used to change the URL-to-filename mapping, then RewriteRule won't see it. If, however, this is done on the same server where the rule is running (not on the back-end proxied server), then you may be able to use a look-ahead to detect it.
Jim
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} /index\.asp$
RewriteRule (/[^.]+\.asp¦/)$ http://192.168.0.102:81$1 [P]
Checking %{REQUEST_FILENAME} causes the execution of this rule to be deferred until the fix-up phase of API processing, when the server has completed URL-to-filename resolution. So the server variable being checked here is the full server path (including %{DOCUMENT_ROOT} to a *file*.
Change the broken pipe "¦" character to a solid pipe character before use; Posting on this forum modifies the pipe character.
Jim
[edit] Removed slash preceding back-reference in substitution URL [/edit]
[edited by: jdMorgan at 5:02 pm (utc) on July 18, 2006]
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} /index\.asp$
RewriteRule (/[^.]+\.asp¦/)$ [192.168.0.102:81$1...] [P]
And it didn't work at all...not even if I explicitly typed index.asp.
So I tried commenting out the Cond line, and it still didn't work.
So I went back to my RewriteRule, and it worked.
So I uncommented the RewriteCond and it kept working, except the [localhost...] part still doesn't redirect when it loads an .asp file.
Any other ideas?
One or more of those, or perhaps a combination, may work. The trick is to find a way to determine what filename the directory URL-request resolves to, so that you'll know if it's index.asp and may need to be proxied through to the back-end. Or to use a fixed URL-name, so that you're sure as soon as the rule matches.
Jim
Anyway, sometimes this is difficult, so proceed at your own risk...
# Rewrite requests for "/" to index.php and exit if index.php exists
RewriteCond %{REQUEST_FILENAME}index.php -f
RewriteRule ^(.*)/$ $1/index.php [L]
#
# Rewrite requests for "/" to index.html and exit if index.html exists
RewriteCond %{REQUEST_FILENAME}index.html -f
RewriteRule ^(.*)/$ $1/index.html [L]
#
# Rewrite requests for "/" to index.htm and exit if index.htm exists
RewriteCond %{REQUEST_FILENAME}index.htm -f
RewriteRule ^(.*)/$ $1/index.htm [L]
#
# If none of the above directory index filetypes exist, proxy requests for "/" to index.asp in the back-end
RewriteRule ^(.*)/$ http://192.168.0.102:81$1/index.asp [P]
#
# Proxy requests for requested .asp files to the back-end
RewriteRule ^/(.*\.asp)$ http://192.168.0.102:81/$1 [P]
Jim
Thanks a bunch for the help!
I got it working with this.
#Special Code so PWS will proxy ASP calls for Apache
RewriteEngine on
RewriteLog ../logs/rewrite.log
RewriteLogLevel 0
# Rewrite requests for "/" to index.php and exit if index.php exists
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME}index.php -f
RewriteRule ^(.*)/$ $1/index.php [L]
#
# Rewrite requests for "/" to index.html and exit if index.php exists
RewriteCond %{DOCUMENT_ROOT}%{SCRIPT_FILENAME}index.html -f
RewriteRule ^(.*)/$ $1/index.html [L]
#
# If none of the above directory index filetypes exist, proxy requests for "/" to index.asp in the back-end
RewriteRule ^(.*)/$ [192.168.0.102:81$1...] [P]
#
# Proxy requests for requested .asp files to the back-end
RewriteRule ^/(.*\.asp)$ [192.168.0.102:81...] [P]