Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

How do I fix a redirect in Firefox so that it leads my site to another address but with a slash at the end of it?

This is my redirect in .htaccess:

RewriteCond %{HTTP_HOST} ^test\.mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.mydomain\.com$
RewriteRule ^testword$ "http\:\/\/outsidedomain\.com\/test\.mydomain\.com\/testword\/" [R=301,L]

It works fine in Chrome.

This is what it's suppose to do:

test.mydomain.com/testword should lead to outsidedomain.com/test.mydomain.com/testword/. Instead, in Firefox it leads to outsidedomain.com/test.mydomain.com/testword. Notice the lack of forward slash.

It has to have a slash at the end because otherwise the script from outsidedomain.com doesn't work properly.

UPDATE: I'm using http://nyanit.com to display a page at my blog so when a user writes mydomain.com/testword it leads to http://nyanit.com/mydomain.com/testword/. It show's all right in Chrome where the "nyanit" script is loaded only once but in Firefox displaying that "testword" page starts a redirection again so the page doesn't show but only the sript is showing multiple times.

Check it out here. Try both Chrome and Firefox to see what I mean.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

This is a classic error, your rule only matches paths which literally match /testword. If you want to redirect everything that begins with /testword, remove the $:

RewriteRule ^testword "http\:\/\/outsidedomain\.com\/test\.mydomain\.com\/testword\/" [R=301,L]

If you want to match /testword and /testword/ and nothing else, make the slash optional by adding /?:

RewriteRule ^testword/?$ "http\:\/\/outsidedomain\.com\/test\.mydomain\.com\/testword\/" [R=301,L]

It looks like that nyanit.com opens http://india.thefalljourney.com/cat/ in your browser. Perhaps you're viewing a cached page in Chromium which is why the redirection is not infinite. The problem is:

  • http://india.thefalljourney.com/cat is redirected to http://nyanit.com/india.thefalljourney.com/cat/
  • http://india.thefalljourney.com/cat/ is opened in a <iframe> by nyanit.com
  • With the rewrite rule, http://india.thefalljourney.com/cat/ is rewritten again... infinite loop.

Suggestion: don't use an Apache redirect for this, but Javascript. If it's detected that the page is in a frame, do not redirect. Put the below JS code on http://india.thefalljourney.com/cat and remove the apache redirection code:

<script>
if (parent == self) {
    location.replace("http://nyanit.com/india.thefalljourney.com/cat/");
}
</script>
share|improve this answer
    
Yes, you're solution is correct but there's obviously a problem with Firefox. When I redirect to outsidedomain.com/test.mydomain.com/testword/, Chrome shows the outside website's script correctly on top of the page from my site but Firefox starts an unlimited loop and loads an outside sripts more than once (indefinitely, actually). Is there a way to fix that? Check out the question update, please. –  user11320 Dec 31 '11 at 14:04
    
@rlesko See updated answer. –  Lekensteyn Dec 31 '11 at 14:21
    
Works perfectly. The only problem now is that there is no sound in Chrome but I'm sure that has nothing to do with the redirect. Doesn't matter actually, thanks for your help... –  user11320 Dec 31 '11 at 15:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.