|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi.
I have the following domains/sub-domains on my Apache. domain.com and dev.domain.com (for development) I have a rule changing function.domain.com?*-> domain.com/cgi-bin/function.pl?* RewriteMap lowercase int:tolower RewriteCond ${lowercase:%{HTTP_HOST}} ^function\.domain\.com$ RewriteRule ^(.+) /cgi-bin/function.pl [PT,L] This part is places (as should) in the virtual host definition of domain.com (in httpd.conf) I want to do the same for dev.domain.com. meaning: RewriteMap lowercase int:tolower RewriteCond ${lowercase:%{HTTP_HOST}} ^function\.dev\.domain\.com$ RewriteRule ^(.+) /cgi-bin/function.pl [PT,L] I thought I should place it in the dev.domain.com virtual host definition. BUT - no when URL is *.dev.domain.com is called - unless its directly dev.domain.com the applying config is that of the domain.com (not dev.domain.com like I though). Is that the proper behavior? What can I do to make *.dev.domain.com go thgough the dev.domain.com virtual host. Coming to think about it - its actually ,ore an Apache question than it is mod_rewrite one, but still... Any idea? ![]() |
|
#2
|
|||
|
|||
|
>> RewriteRule ^(.+) /cgi-bin/function.pl [PT,L]
First off, if you want everything in under your REQUEST_URI of / to be handled by /cgi-bin/function.pl, use a internal redirect with a ruleset like so: RewriteRule ^(.+) /server/path/no/symlink/to/function.pl [T=application/x-httpd-cgi,L] [PT,L] is usually used to bypass rewriting. For example: RewriteRule ^/icons/(.+) - [PT,L] /icons directory is reserved for global use, so don't mess with it. Your ruleset might not work with the REQUEST_URI is exact /cgi-bin/function.pl, so you would do this right after your RewriteCond like so: RewriteRule ^/cgi-bin/function\.pl$ - [PT,L] Next, are you sure your domain have wildcard enabled? If so, just setup a ServerAlias for that. Your whatever.dev.domain.com MUST be DNS resolvable before you can do this. |
|
#3
|
|||
|
|||
|
Hey. (hi freebsd)
What I do now is this... (and it seems to be working) ________________________________ <VirtualHost my.ip.add.ress> ServerAdmin webmaster@dev.myd.com DocumentRoot /var/www/html/dev.myd.com ServerName dev.myd.com ServerAlias dev.myd.com www.dev.myd.com clicks.dev.myd.com login.dev.myd.com ErrorLog logs/dev.myd.com-error_log CustomLog logs/dev.myd.com-access_log common ScriptAlias /cgi-bin/ /var/www/cgi-bin/dev.myd.com/ ErrorDocument 404 http://dev.myd.com/cgi-bin/traffic/click.pl?36 Rewritelog logs/rewrite.dev.log RewritelogLevel 9 RewriteEngine on RewriteMap lowercase int:tolower RewriteCond ${lowercase:%{HTTP_HOST}} ^clicks\.dev\.myd\.com$ RewriteRule ^(.+) /cgi-bin/traffic/click.pl [PT,L] RewriteCond ${lowercase:%{HTTP_HOST}} ^login\.dev\.myd\.com$ RewriteRule ^(.+) /cgi-bin/login.pl [PT,L] </VirtualHost> __________________________________ So I am wondering what you meant by RewriteRule ^(.+) /server/path/no/symlink/to/function.pl [T=application/x-httpd-cgi,L] and the potential problems the [PT,L]. Can you clarify whats wrong with my above solution? Thnk you. |
|
#4
|
|||
|
|||
|
When you want to force REQUEST_URI of anything to be handled by a script, that's equivalent to using ErrorDocument like so:
ErrorDocument 404 /cgi-bin/error.cgi?404 Apache will need further processing to determine the MIME type of the handler - error.cgi. Like ScriptAlias directive, every file in your scriptalias'ed cgi-bin will have a MIME type of application/x-httpd-cgi enforced. For your case, [PT] (pass thru) would work but it's no longer the ideal way to deal with a straight internal redirect as: RewriteRule ^(.+) /cgi-bin/traffic/click.pl [PT,L] because click.pl is not a static file but a CGI script. Therefore, according to mod_rewrite doc, 'passthrough|PT' (pass through to next handler), you are doing extra processing to determine what handler should handle to process click.pl, and it really is a CGI (or even mod_php script with application/x-httpd-php) which is unnecessary when you can tell Apache, hey, trust me, that click.pl has a application/x-httpd-cgi MIME type. Further, what pass-thru really means is to tell mod_rewrite, hey this is beyond your duty so just ignore it and let the responsbile person (the handler) to handle it. Like I said in my previous example: RewriteRule ^/icons/(.+) - [PT,L] /icons/ directory is reserved for global use because it's handled by mod_alias like so: Alias /icons/ "/www/icons/" so it's beyond mod_rewrite's duty and the [PT] is then being used appropriately here. |
|
#5
|
|||
|
|||
|
Hi.
Hey Freebsd. Thx for that explanation. That part is totally clear now. The only question I still have regarding this is: How do I make it work so only the http://login.dev.myd.com/ and http://login.dev.myd.com will go to the function, while all the rest (like login.dev.myd.com/images/log.gif) will not be effected. This is because I only want the login.dev.... to go to the login.pl while images and other redirection should not be redirected to the cgi. |
|
#6
|
|||
|
|||
|
Every request under http://login.dev.myd.com/ will hit your RewriteCond regardless which ruleset you have. You will need to figure out if you really have that many other stuff (images/log.gif) then change the priority of your condition to give you the fastest and most efficient result.
For instance, RewriteEngine on RewriteMap lowercase int:tolower RewriteCond ${lowercase:%{HTTP_HOST}} ^login\.dev\.myd\.com$ RewriteRule ^(.+) /server/path/to/cgi-bin/login.pl [T=application/x-httpd-cgi,L] A request of (1) clicks.dev.myd.com/* as well as (2) login.dev.myd.com/*. To minimize the chance for requesting (1) clicks.dev.myd.com, the rule of thumb is to create ANOTHER unique <VirtualHost> block for login.dev.myd.com so your RewriteCond {HTTP_HOST} is now obsolete and you just need to deal with the (2) part. Here is an example: Code:
<VirtualHost my.ip.add.ress>
ServerAdmin webmaster@dev.myd.com
DocumentRoot /var/www/html/dev.myd.com
ServerName login.dev.myd.com
#ServerAlias dev.myd.com www.dev.myd.com clicks.dev.myd.com login.dev.myd.com (this line is gone)
ErrorLog logs/login.dev.myd.com-error_log
CustomLog logs/login.dev.myd.com-access_log common
ScriptAlias /cgi-bin/ "/var/www/cgi-bin/dev.myd.com/"
ErrorDocument 404 http://dev.myd.com/cgi-bin/traffic/click.pl?36
RewriteEngine on
Rewritelog logs/rewrite.dev.log
#RewritelogLevel 9 (this is for debugging only)
#RewriteMap lowercase int:tolower (this is gone, we don't need to deal with HTTP_HOST in
rewrite condition because it's handled by virtualhost)
#RewriteCond ${lowercase:%{HTTP_HOST}} ^login\.dev\.myd\.com$
# if you have a lot of images, add this
RewriteRule ^/icons/(.+) - [PT,L]
RewriteRule ^/images/(.+) - [PT,L]
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^(.+) /server/path/to/cgi-bin/login.pl [T=application/x-httpd-cgi,L]
</VirtualHost>
Last edited by freebsd : March 3rd, 2002 at 06:38 AM. |
|
#7
|
|||
|
|||
|
hey.
It seems to me like its "little too much" to define a vhost just for functions. assuming I have/will-have many functions, like submit.dev.myd.com (going to submit.pl), login.dev.myd.com, click.dev.myd.com, signup.dev.myd.com, report.dev.myd.com. each going to his special function. All I want to do is redirect the "clean" calls (those with only QUERY_STRING - but no REQUEST_URI) to the script while leaving those calls to files (images, scripts, etc... - Tose with non-empty REQUEST_URI) under those aliases free from my intervention. Isn't it more sensible to do it with mod_rewrite that with vhosts? maybe it could be done by: RewriteCond ${lowercase:%{HTTP_HOST}} ^function\.dev\.myd\.com$ RewriteCond %{REQUEST_URI} ??IS_EMPTY?? RewriteRule ^(.+) /server/path/to/cgi-bin/function.pl [T=application/x-httpd-cgi,L] is there a way to do this ??IS_EMPTY?? thing? wont it solve my problem efficiently? BTW: dont I have to chain the QEURY_STRING to the Rewrited URL? like: RewriteRule ^(.+) /server/path/to/cgi-bin/function.pl\?%{QUERY_STRING} [T=application/x-httpd-cgi,L] It somehow works even without - I wonder why? |
|
#8
|
|||
|
|||
|
>> It seems to me like its "little too much" to define a vhost just for functions
If you take a close look at your rewrite.log, defining each for a dedicated vhost is not too much, but consumes a lot fewer resource, thus more efficient. When your RewriteCond ${lowercase:%{HTTP_HOST}} within a <VirtualHost> has too many FQDNs. Even if you only want to match ^function\.dev\.myd\.com$, ^whatever\.dev\.myd\.com$ will still go thru your first condition to match against. When you do the way I suggested previously, you can remove the first condition entirely. Imagine you have a.dev.myd.com to z.dev.myd.com, each request will try to match against your 1st condition, that wastes a lot of resource. >> is there a way to do this ??IS_EMPTY?? thing? There is no such thing as an empty REQUEST_URI, it has / at the very least. >> dont I have to chain the QEURY_STRING to the Rewrited URL? Yes, but I don't see where QUERY_STRING is coming from when someone requests http://function.dev.myd.com/ You should already know that the default RewriteCond is %{REQUEST_URI}, when you need to switch from that to %{QUERY_STRING}, you need to chain it with [C] so it can carry the rewrite over to the next rule to perform actual rewriting. |
|
#9
|
|||
|
|||
|
Hey freebsd.
>> vhost is not too much, but consumes a lot fewer resource, thus more efficient. makes sense - point taken - done >> Yes, but I don't see where QUERY_STRING is coming from when someone requests http://function.dev.myd.com/ Its: click.dev.myd.com?123 -> dev.myd.com/cgi-bin/click.pl?123 Thats why the QUERY_STRING (=123) was mentioned. >> You should already know that the default RewriteCond is %{REQUEST_URI}, when you need to switch from that to %{QUERY_STRING}, you need to chain it with [C] so it can carry the rewrite over to the next rule to perform actual rewriting. Can you clarify the [C] issue? >> There is no such thing as an empty REQUEST_URI, it has / at the very least. What I mean is that / is "empyt". What I'm doing now (in the login.dev.myd.com vhost) is: RewriteRule ^/icons/(.+) - [PT,L] RewriteRule ^/images/(.+) - [PT,L] RewriteRule ^/cgi-bin/(.+) - [PT,L] RewriteRule ^(.+) /var/www/cgi-bin/dev.myd.com/login.pl [T=application/x-httpd-cgi,L] while I only need the login.dev.myd.com to be redirected to /var/www/cgi-bin/dev.myd.com/login.pl i have to state all the preceeding rewrite rules to avoid changind the /icons .images /cgi-bin etc.. is there a way to automatically prevent rewriting of all /[something-that-is-not-empty] so that everything that is http://login.dev.myd.com/*will not be touched while only http://login.dev.myd.com and http://login.dev.myd.com/ will be converted? |
|
#10
|
|||
|
|||
|
>> Its: click.dev.myd.com?123 -> dev.myd.com/cgi-bin/click.pl?123
It needs to be click.dev.myd.com/?123 you can't leave out the slash. >> everything that is http://login.dev.myd.com/*will not be touched You need at least one RewriteCond such as: RewriteCond %{REQUEST_URI} !^/[0-9]+$ >> Can you clarify the [C] issue? You don't need to chain it when there is no HTTP_HOST matching condition. Here is an example that needs to use [C]: Code:
RewriteEngine on
RewriteMap lc int:tolower
RewriteCond %{SERVER_NAME} ^[^.]+\.domain\.com$ [NC]
RewriteRule ^/icons/(.+) - [PT,L]
RewriteRule ^(.+) %{SERVER_NAME}=$1 [C]
RewriteRule ^(.*)=(.*) ${lc:$1}$2 [C]
RewriteRule ^([^.]+)\.domain\.com(.*) /var/www/domain.com/$1$2
Like I said, the default condition is to match against REQUEST_URI, in this example, however, I am doing all the rewriting on the SERVER_NAME part, then chain it so my very last rewriterule is doing the REQUEST_URI rewriting. No matter what you do, the final condition must have something to do with REQUEST_URI condition, because that's what Apache sends back to the browser. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > Apache and sub-domains: mod_rewrite |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|