Please, help me capturing

Topics: User Forum
Jan 31, 2010 at 11:38 AM

Hi everyone.

I'm just crazy to get this rule working.
I'd like that:
If host is .es or .de just rewrite to /es or /de and append the incomming url when url is not in the following list.

I've tried a lot of sentences but I can't never use *1 and $1 in the rewrite

RewriteCond %{HTTP_HOST} ^www\.mysite\.(es|de)$ [I]
RewriteCond ^/(.*)$ !(^404\.asp$|^estilo\.css$|^funciones_js\.asp$|^favicon\.ico$|^validaFormESP.asp$|^validaFormENG.asp$|^validaFormFR.asp$|^calendar-blue.css$|^/js/|^images/|^imagenes/|^flash/|^galeria/?|^buscador/?) [I]
RewriteRule ^/(.*)$ /*1/$1 [I,L]

There is no error or warning in log files. And this are the results:

Sun Jan 31 13:33:01 -  3096 - EvalConditionList: rule 6, TRUE, Rule will apply
Sun Jan 31 13:33:01 -  3096 - ReplaceServerVariables: in='/*1/$1' out='/*1/$1'
Sun Jan 31 13:33:01 -  3096 - GenerateReplacementString: result '//'
Sun Jan 31 13:33:01 -  3096 - EvaluateRules: Result (length 2): //
Sun Jan 31 13:33:01 -  3096 - EvaluateRules: Last Rule
Sun Jan 31 13:33:01 -  3096 - EvaluateRules: returning 1
Sun Jan 31 13:33:01 -  3096 - DoRewrites: Rewrite Url to: '//'

Thank you very much!

Coordinator
Jan 31, 2010 at 3:37 PM

Ok, your first RewriteCond looks good - it makes sense.  I think it is doing what you want.

The second RewriteCond is incorrect.  I think you're confusing the syntax and usage for RewriteRule with RewriteCond.    For the 2nd RewriteCond, you've specified ^/(.*)$  for your "test-string", to use the terminology from the documentation.   But that is really a pattern, a regular expression.  I think you probably want to apply a pattern to the incoming URL.  To do that, you would use %{URL} as the test string.  like this: 

RewriteCond %{HTTP_HOST} ^www\.mysite\.(es|de)$ [I]
RewriteCond %{URL} !(^404\.asp$|^estilo\.css$|^funciones_js\.asp$|^favicon\.ico$|^validaFormESP.asp$|^validaFormENG.asp$|^validaFormFR.asp$|^calendar-blue.css$|^/js/|^images/|^imagenes/|^flash/|^galeria/?|^buscador/?) [I]
RewriteRule ^/(.*)$ /*1/$1 [I,L]

Another thing you can try while developing this stuff: decompose it into smaller problems, and combine it into a final solution when each smaller problem is solved. For example, you could work out each condition separately. Get the first RewriteCond working, so that es/de is behaving the way you think it should. Then, separately, get the other RewriteCond working. When they both are working, combine them.