Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mod_rewrite and DirectoryIndex

Status
Not open for further replies.

apparition

Technical User
Aug 8, 2001
34
US
I have Apache 2.0 installed on a WinNT4 box coexisting with IIS which I moved to port 81. Apache handles everything except for the ASPs. I used mod_rewrite to change and urls that contain "asp" to port 81 like this:


RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)asp(.*)$ [NC]
RewriteRule ^.*$


Some of my directories contain only asp applications so I also added index.asp and default.asp to the DirectoryIndex directive for the site so that people don't get broken links.

The problem is that while the rewrite works for urls with the full file name, if someone goes to a directory and does not specify the file name (i.e. default.asp), the url is not rewritten to port 81 because there is no file name containing "asp" and apache tries to parse the vbscript! I could put a redirect page in there but that is sloppy.

Is there a way to get the file name even if the user requests just the directory? I tried to use the REQUEST_FILENAME variable but it looks like the actual file name is not there either.

Any ideas?
 
Thanks for the suggestion...

Yes, I did try it with SCRIPT_FILENAME and got the same result. It didn't see the "asp" in SCRIPT_FILENAME.

I tried to test the different variables in a SSI (shtml) file with the <!--#echo var=&quot;VARIABLE&quot; -->. It shows the actual file name in REQUEST_URI when I test it that way! But when I use it in the mod_rewrite script, it is not there. I'm not sure whats going on any more...

Am I explaining it ok or should I give more info?
 
OK I think I finally got it. I just thought I'd come back and let any future readers know how this should be done since I could find nothing about it. Its not exactly what I wanted but it works.

I'm just going to add seperate RewriteConds for each directory that has an index.asp or default.asp. Then for any future development in asp, I'm going to have a seperate directory for ASp files and that whole diretory and anything under it will be forwarded over to IIS.

Something like this:
Code:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/(.*)asp$
RewriteRule ^(.*) [URL unfurl="true"]http://12.34.56.78:81$1[/URL] [P,L]
RewriteCond &{REQUEST_URI} ^/scripts/win32(.*)$
RewriteRule ^(.*) [URL unfurl="true"]http://12.34.56.78:81$1[/URL] [P,L]
RewriteCond &{REQUEST_URI} ^/asp(.*)$
RewriteRule ^(.*) [URL unfurl="true"]http://12.34.56.78:81$1[/URL] [P,L]

Thanks to freebsd in the devshed apache forum for this workaround.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top