Forum Moderators: phranque

Message Too Old, No Replies

require a customer to visit a page

use mod_rewrite to control site access

         

chucker

8:04 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



Hello All,
My business is moving to a new location..so I'd like to have all customers who access my site view a "notice" page that informs them of the move.
Once they see the notice, I'd like them to be free to browse the site.
The site is now hundreds of pages in size, and customers enter the site through almost all of them.
Since all the pages are just text with no frames or anything, it seems like the most efficient way for me to make sure that every visitor to the site sees the notice is to use mod_rewrite. I'd like to "funnel" all page requests to the notice page and there, provide links to the rest of the site.
Then the customer should be able to browse the site as usual.

but, when clicking on a link from within mysite.com, .htaccess always returns a "notice" page.

Here's what's in my .htaccess file..

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER}!^www.mysite.com/ [NC]
RewriteRule .* [mysite.com...]

I am brand new to this, and butting up against a deadline..Anyone have any suggestions?

jdMorgan

10:14 pm on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chucker,

Welcome to WebmasterWorld [webmasterworld.com]!

You'll have a problem with users having blank referrers being unable to see anything but your notice page. Internet security software and caching proxies between you and your visitor may drop the referrer, and the visitor may well be unaware of it, thus making your site look 'broken'.

I would suggest using cookies instead, but nothing is bullet-proof. Some visitors may have cookies disabled as well.

You could also allow blank referrers, but then those users would bypass your "We're moving" page.

Have you considered using SSI to include a simple header on each page announcing the move? The header could contain a link to a page with all the details. Or do you have a checkout page, or some other page that most users end up going to eventually?

Just some ideas...

Jim

chucker

10:43 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



Hi Jim,
thanks for the suggestions..

Nothing here is going to bat 1.000, I guess..
Seems like allowing the blank referers would be preferable to a broken site.
If I could just arrange this so that a customer following a link on "notice" could get on further into the site, that'd be pretty good. right now, even when I'm actually in the site, clicking a link to a page which is contained in the directory that also contains the .htaccess file returns the "notice". It is not allowing a visit from within the site.

I am not yet familiar with SSI, though I guess I could learn..

Also not sure how to use cookies..
I had seen a thread on WebmasterWorld with some code such that once a visitor had seen a page, it would set a cookie and he'd not have to see the same page again on a return visit..that sounds kind of complex for me right now..
I could change a picture that's called for on each page to ask a visitor to look at the new location for the biz, but honestly, I don't trust visitors to "click here" on their own when it's this
important...hehe/
we don't have a "check out page"..customers make too many bad decisions to let them buy without a little consultation, so we require a phone call. our return rate is so close to zero it'd scare you!

jdMorgan

11:12 pm on Mar 2, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's as close as you can get with a good old unreliable HTTP_REFERER check:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_REFERER} .
RewriteCond %{HTTP_REFERER} !^(www\.)?mysite\.com [NC]
RewriteCond %{REQUEST_URI} !^/notice\.html$
RewriteRule \.html$ http://www.mysite.com/notice.html [R=302,L]

This adds a RewriteCond to permit blank referers to bypass the notice page, so they won't get trapped there. It also includes another new RewriteCond to prevent an infinite redirection loop. I also added the restriction that only html page requests are redirected, since there is no use trying to redirect images, scripts, CSS, etc. to an html page.

Actually, I like your replace-the-common-image idea, and you might want to use both. If you are on a short fuse, there's no use risking a major technical problem with cookies or any other new technology right now.

Jim
<edit> Fixed typo </edit>

[edited by: jdMorgan at 4:34 am (utc) on Mar. 23, 2004]

chucker

11:38 pm on Mar 2, 2004 (gmt 0)

10+ Year Member



Jim,
I see the wisdom in using both the .htaccess and the "replace-the- common-image" in tandem. That will get some fraction of the blank referrers, at least. As we are in the prime viewing times for my site for the next few hours, I'll try your suggested mod-rewrite code early tomorrow morning.

So is it correct that once you type "http://", regex escape backslashes for the "." are not necessary/wrong? I haven't been able to find any clear rules on this...(low priority)

Thanks again for everything,
Chuck

jdMorgan

12:10 am on Mar 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The confusing issue with your http:// question is that the string on the *right* of a RewriteCond is a regex pattern, and the string on the *left* in a RewriteRule is a regex pattern. The string on the *right* of a RewriteRule is a literal substitution string, except that it may contain server environment variables and back-references to local RewriteCond- and RewriteRule-defined variables. It can also be followed by optional flags -- [R=301,L] for example. Character escape sequences are only used in regex patterns, so that's why you don't see them in the substitution string of a RewriteRule.

The best source for mod_rewrite info is the Apache mod_rewrite [httpd.apache.org] documentation itself. It's a bit impenetrable at first, but if you have an existing, working RewriteRule, you can dig through the RewriteRule and RewriteCond documentation and figure out how it works.

Jim

chucker

2:08 pm on Mar 3, 2004 (gmt 0)

10+ Year Member



Jim,
when I use the new instructions the server returns a 500 error. this is when requesting a page from links within my site.
I wish the writers of the Apache docs had a better knack of explaining things in English..but Apache org has been the main resource I've used to get this far.
Chuck

jdMorgan

6:25 pm on Mar 3, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chucker,

The first thing to do when you get a 500-Server Error is to go to your error log file. It often will identify the problem for you, sometimes quite specifically.

This problem may be my fault - make sure you see the correction I posted in the code above.

Jim

chucker

1:19 am on Mar 4, 2004 (gmt 0)

10+ Year Member



Jim,
I checked the error log early this morning..it's empty. I will contact our host about that..by now you'd think it'd have some content, hehe. to be cont'd..
Chuck

jdMorgan

2:12 am on Mar 4, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The error log is typically purged nightly.

Jim

chucker

2:36 pm on Mar 6, 2004 (gmt 0)

10+ Year Member



Hi Jim,
In fact, nothing was being written to my error page! the site has since been restarted and work is progressing.
here's what I've got now..I added a few things to your suggestions and it seems to be working! What do you think?
I added the REMOTE_HOST stuff to control people who enter the site through bookmarks in their browsers..The server didn't seem to like REQUEST_URI so I guessed and changed it to REQUEST_URL and expanded the file path..

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REMOTE_HOST}!^(www\.)?mysite\.com [NC]
RewriteCond %{HTTP_REFERER} .*
RewriteCond %{HTTP_REFERER}!^(www\.)?mysite\.com [NC]
RewriteCond %{REQUEST_URL}!^(www\.)mysite\.com/notice\.html$


RewriteRule \.html$ [mysite.com...] [R,L]

thanks,
Chuck

No, this is not quite right. when I follow links from the notice page and try to get back to a product description page, I am still being redirected to the notice. Being in the site doesn't exclude me from the redirect back to the notice.I wind up in a loop .(hope this is clear..)

chucker

2:31 am on Mar 9, 2004 (gmt 0)

10+ Year Member



Jim,
I have gone back to your original suggestion, but the redirection still happens from links within my site.
How can I exclude my site links from being redirected?
thanks,
Chuck

jdMorgan

1:41 am on Mar 15, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chucker,

The code we developed above is intended to do what you want, but something is just not quite right. Since I don't have access to all of your test results, I'm afraid I can't tell why it does not work - This is very "standard" code for a very "standard" application. I encourage you to keep testing and tweaking the code - at the very least you will begin to understand how it works, and that will undoubtedly help you find a solution.

Jim

chucker

2:51 am on Mar 23, 2004 (gmt 0)

10+ Year Member



Jim,
As I get it, the standard code is supposed to redirect clients who come from outside "mysite". and not affect clients already in "mysite". the actual result so far is that all clients regardless of origin are redirected to the notice page. Ahh, not good.
I will keep playing with this. In the meantime, i have set up the "common jpeg" with a message and a simple .htaccess redirect from "index" to "notice" and folks seem to be getting the idea.
thanks for your help and encouragement!
Chucker

jdMorgan

4:40 am on Mar 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



chucker,

Yes, the code says, "If the referrer is non-blank and is not our own site, and the requested URI is not the notice.html redirect page, then redirect all requests for html files to the notice.html page."

I just spotted another "typo" in the code I posted - a rather large error. The first three lines should be RewriteCond directives, followed by a single RewriteRule. See the amended post (msg #4) above.

Jim