Forum Moderators: phranque

Message Too Old, No Replies

domain forcing with mod_rewrite

         

phoenix_fly

2:31 am on May 26, 2005 (gmt 0)

10+ Year Member



Hello Jim and everybody,

Sorry, but every time I think I mastered mod_rewrite, the beast makes me go back to my misery! So, I will count on you guys to help me out one more time!

Now I am trying to force a redirect to a domain with ".br" at the end, wich stands for my country.

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.mysite\.com\.br [NC]
RewriteRule (.*) [mysite.com.br...] [R,L]

It doesnīt work. By the way, I have the two domains maped to my www root, and they open with no problems each one of them. But this redirect just doesnīt work.

Iīve tried the [R=301,L] also, with no success. I am using the R because I want the userīs adress bar to change, showing the forced domain.

phoenix_fly

jdMorgan

3:18 am on May 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Please be specific. What do you mean by "it doesn't work"? There are many possibilities:

Does it do nothing?

Does it redirect to the wrong domain?

Do you get a server error? If so, what does the server error log say?

Do you have other working rules in this .htaccess file?

[added] One more: Did you flush your browser cache as required before testing? [/added]

The better your description, the more likely that you will get a fast answer.

Jim

sitz

10:46 pm on May 26, 2005 (gmt 0)

10+ Year Member



<pedant>
You may want to write this:

RewriteRule (.*) http://www.mysite.com.br/$1 [R,L]

...as this:

RewriteRule ^/(.*) http://www.mysite.com.br/$1 [R,L]

...if your RewriteRule lines are in your httpd.conf, since you may get a double '/' in the URL you're redirecting to otherwise.

phoenix_fly

2:18 pm on May 27, 2005 (gmt 0)

10+ Year Member



Hello Jim and sitz,

Sorry, the problem is that nothing happens. Just like if the rule wasnīt there. Yes, I have other rules in the .htaccess, but I made this the first one, as I think I should, right?

phoenix_fly

2:32 pm on May 27, 2005 (gmt 0)

10+ Year Member



Hey, Iīve just added a ^ at the beginning of the rule:

RewriteRule ^(.*) [mysite.com.br...] [R,L]

and it seems to have worked!

Seems because I am redirected to a 401 error page. I think itīs because, during the beta-tests, Iīve made authentication required. And maybe the redirect from mod_rewrite doesnīt understand that, doesnīt give the chance for the visitor taht typed the .com domain to be prompted for the username and password.

May be that?

jdMorgan

5:06 pm on May 27, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Not sure I understand your question, but two facts come to mind:

1) Mod_auth takes precedence over mod_rewrite on properly-configured systems.
2) You must always flush your browser cache before testing any new code.

One or both of those may affect this situation.

Jim

phoenix_fly

7:23 pm on May 30, 2005 (gmt 0)

10+ Year Member



Hello Jim and Sitz

Everything is working just fine now. I talked to my host's network administrator and heīs put the rule at the .conf file of apache, instead of in my .htaccess, and it worked!

Thanks a lot,

phoenix_fly