Keep Server Online
If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.
or
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.
| |
|
Topic: mod_rewrite to COM1.shtml is forbidden - but I need it |
|
Author |
|
huygens1962
Joined: 17 Apr 2008 Posts: 2
|
Posted: Thu 17 Apr '08 0:26 Post subject: mod_rewrite to COM1.shtml is forbidden - but I need it |
|
|
I have set up an expression to rewrite my dynamic URLs to static ones. And it almost works 100%...
Here's my expressions:
Code: |
RewriteRule ^([a-z]+)\.shtml$ stamps/script1.php?ent=$1 [NC,L]
RewriteRule ^([a-z]+)([0-9]+)\.shtml$ stamps/script2.php?ent=$1&set=$2 [NC,L]
|
And they work except for when I have certain pages that begin with "com"
com1.shtml should map to "stamps/script2.php?ent=com&set=1"
It fails, with this log entry:
Code: |
[Wed Apr 16 16:53:33 2008] [error] [client 127.0.0.1] Forbidden: G:/Spacestamps/com1 doesn't point to a file or directory, referer: http://localhost/com.shtml
|
I suspect that com1.shtml through com9.shtml are somehow reserved in Windows, because those generate forbidden errors. My rewrites for com10.shtml and higher work flawlessly.
Is there any way I can configure Apache to process those rewrites and build my queries? Or am I going to have to write some sort of special case handling for com1.shtml - com9.shtml?
TIA. |
|
Back to top |
|
tdonovan Moderator
Joined: 17 Dec 2005 Posts: 611 Location: Milford, MA, USA
|
Posted: Thu 17 Apr '08 2:39 Post subject: |
|
|
The problem isn't in Apache, but in Windows itself.
com1 (upper or lower case, with or without an extension) is a reserved device name, not a file name.
See Microsoft's note about Naming a File.
Quote: | Do not use the following reserved device names for the name of a file: CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9. Also avoid these names followed by an extension, for example, NUL.tx7. |
I don't see any way to get around this problem with configuration directives on Windows.
Early in the request processing Apache calls a Windows function to test if each segment of the URI is 1) a "file", 2) a "directory", 3) "doesn't exist".
It is OK if it doesn't exist, mod_rewrite might take care of that in a later step - but if Windows says it is a "device" the request is immediately forbidden.
This all happens before mod_rewrite, so any device name (in any segment of the URI) will never make it to your RewriteRule.
-tom- |
|
Back to top |
|
huygens1962
Joined: 17 Apr 2008 Posts: 2
|
Posted: Thu 17 Apr '08 4:01 Post subject: |
|
|
I found a left-handed way around it: I stuck a zero in between:
Code: | if ($stampset<'10') { $zero='0'; } else { $zero=''; };
... a href='/$issuer$zero$stampset.shtml'
|
which gives me com01.shtml, gets to the point that Apache can rewrite it and works like a charm.
Thanks for your input - I suppose we can mark this closed. |
|
Back to top |
|
|
|
|
|
|