Forum Moderators: phranque

Message Too Old, No Replies

How to escape a redirect loop

to many redirects

         

Austin

2:27 am on Apr 28, 2007 (gmt 0)

10+ Year Member



Hello
I have 2 different redirects in a conflict. I'd like to redirect all visitors from outside to "home.html" and they can access "index.html" or a sub domain from there (because there are 2 companies sharing 1 domain - I took 1 off to a subdomain).

My htaccess file:
I made custom 404+403

A force-WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.xx [NC]
RewriteRule ^(.*) [domain.xx...] [R=permanent,L]

..and that is the problem - my redirect to home.html. I've looked all over and tested several tips I've found - all gives me a 500 misconfiguration.

I'd like to put in something like:
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^http://(www\.)?domain\.xx(/)?.*$ [NC]
"RewriteRule them from index ---> /home.html"

...the then back to index...

I also tested a javascript tht does the same thing just to prevent the Error500, but then I had a loop... (was just loading on)

I hope you understand my explanation? :)

Is there a workaround? Is this possible? ..without removing the 403 page and the force-www?

Thanks in Advance!
I'd really like this one to work.

jdMorgan

4:03 am on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The general fix is to examine the server variable %{THE_REQUEST} to differentiate between a client-requested URL and a URL resulting from an internal rewrite.

However, the details here as to which page is on which domain are sketchy and unclear, so that's all I can offer on that subject.

Your best bet is to put up a "lobby" page and let the user select which site is desired; Any automation based on %{HTTP_REFERER} will fail as often as not, because many visitors requests will not provide a referrer, either because their "internet security" software blocks it (and perhaps without their knowledge), or because they are behind corporate or ISP caching proxies (e.g. All of AOL), which also will not provide a referrer. Referrers can also be easily spoofed. Basically, the HTTP referrer is almost completely unreliable.

Jim

Austin

5:01 pm on Apr 28, 2007 (gmt 0)

10+ Year Member



Thanks for the quick reply.
Yes, the referal can be hard to use/work. What about "Host" insted - like in the force-www?

Here's the full htaccess-file:

<Files .htaccess>
order allow,deny
deny from all
</Files>

AddHandler server-parsed .html

Options All -Indexes +FollowSymLinks

# stop hot-linking
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?example\.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?sub.example\.com(/)?.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?another\.site\.com(/)?.*$ [NC]
RewriteRule .*\.(jpg¦gif¦png)$ - [F,NC]

# force-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*) http://www.example.com/$1 [R=permanent,L]

# sub domain
RedirectMatch permanent ^/sub/.*$ [sub.example.com...]

ErrorDocument 403 /403.html
ErrorDocument 404 /404.html

# # # # #

Navigation today:
example.com/ (index.html) = "lobby-page" with 2 links to..
-» example.com/folder/file1.html
-» example.com/folder/file2.html

My idea is to get a clearer picture who's who sort of. By giving each on their own index as in example.com/(index.html) and company2 sub.example.com/index.html) but to catch incomers to this "lobby-page".

Hope this cleared up the sketch. :)

I start to belive I have to give up the custom 403 page to get this work, but it would be nice to keep that on in there.

Thanks
/Eric

jdMorgan

7:19 pm on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm sorry, I don't know what the question is...

I would advise, however, that you don't mix mod_alias and mod_rewrite directives. If you do, you won't have control of which executes first on any given server. I'd recommend replacing:


# sub domain
RedirectMatch permanent ^/sub/.*$ http://sub.example.com/$1

with

# sub domain
RewriteRule ^sub/(.*)$ http://sub.example.com/$1 [R=301,L]

and put this directive *above* the non-www to www- domain redirect. Otherwise, you'd get stacked redirects if a request for example.com/sub was received -- first to www.example.com/sub, and then to sub.example.com. While page rank and link popularity can be passed through one redirect, they won't be reliably passed through two.

The custom 403 and 404 pages should have nothing to do with the rest of this.

Jim

g1smd

7:55 pm on Apr 28, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Does a request for the non-www version of /sub/ result in a redirection chain?

You need to make sure that it does not.

Ah, jd got there first.

Austin

1:21 am on Apr 29, 2007 (gmt 0)

10+ Year Member



Oh.. Thanks. I'll try put that one before and see.

The htaccess file works fine as it is now. No chains and it loads as I want it so far. My problem is that I do get the 500Error and a loop when I want to try making an additional redirect to the home.html (the "lobby-page") Like I wrote in my first post:

###
I'd like to put in something like:
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?domain\.xx(/)?.*$ [NC]
"RewriteRule them from index ---> /home.html"

...the then back to index...
###

And all of those different versions I've tried to make it work - that's where it failes.

OK - I'll go back and try this now and see what's happening.

Thanks again.

/Eric