LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-19-2009, 09:11 AM   #1
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Rep: Reputation: 15
.htaccess question


Hi, I'm going to be upgrading a website and was hoping to allow 1 IP address to view it during the upgrade process (mine), and any other IP except mine to redirect to another page.

How can I do that with .htaccess?
 
Old 11-19-2009, 09:17 AM   #2
SethsdadtheLinuxer
Member
 
Registered: Jun 2007
Posts: 152

Rep: Reputation: 37
use a combination rewritecond and rewrite rule
see
http://www.webweaver.nu/html-tips/web-redirection.shtml
and
http://httpd.apache.org/docs/1.3/mod...ml#RewriteRule
 
Old 11-19-2009, 09:45 AM   #3
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Original Poster
Rep: Reputation: 15
With this code, what does "RewriteRule \.html$" from part of the last line do?

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123\.45\.67\.89
RewriteRule \.html$ /alternate_page.html [R=302,L]
 
Old 11-19-2009, 04:32 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,788

Rep: Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590
Hi,

This is not going to work. The regex \.html$ means everthing that ends in .html, so in your case when other people visit a html page they will be redirected to alternate_page.html, that also ends in .html, so you'll have a loop. Besides that everyone can see other stuff like images, php files etc.
You should use something like that:
Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^123.45.67.89
RewriteCond %{REQUEST_URI} !^/alternate_page.html$
RewriteRule ^(.*) http://%{HTTP_HOST}/alternate_page.html [L]
Regards
 
Old 11-19-2009, 06:19 PM   #5
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Original Poster
Rep: Reputation: 15
When I use this code, the idea works, but upgrade.html still shows in the main page that only my IP address can see. Any ideas on that?

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REMOTE_HOST} !^23.27.254.134
RewriteCond %{REQUEST_URI} !^/upgrade.html$
RewriteRule ^(.*) http://%{HTTP_HOST}/upgrade.html [L]
 
Old 11-20-2009, 12:07 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,788

Rep: Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590
Don't get it. Isn't upgrade.html the page you want your users to be redirected?
 
Old 11-20-2009, 05:38 AM   #7
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Original Poster
Rep: Reputation: 15
Yes is is. My site is in PHP the IP block works but when I view it I see the website plus the upgrade.html embeded either behind my site or showing as part of the site. How can I fix that?
 
Old 11-20-2009, 05:49 AM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,788

Rep: Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590
Still don't get it.
upgrade.html is under the document root of your site, so it's normal to see it, if you request it.
If you don't want the page to be under your document root, you can redirect the users to a vhost, or something like that. In that case you don't the 2nd line and the last line should be:
Code:
RewriteRule ^(.*) http://vhost.domain.com/upgrade.html [L]
 
Old 11-20-2009, 06:06 AM   #9
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Original Poster
Rep: Reputation: 15
Sorry about that, I'm good for maiking myself unclear.

When my IP is the only one allowed to see the site, I'm seeing both the site and the upgrade page at the same time.

The Block WORKS for everyone else!

Please see the attached files
Attached Thumbnails
Click image for larger version

Name:	Seeing This.jpg
Views:	8
Size:	132.6 KB
ID:	2018   Click image for larger version

Name:	SHOULD BE seeing this.png
Views:	8
Size:	161.8 KB
ID:	2019  
 
Old 11-20-2009, 06:37 AM   #10
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,788

Rep: Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590
It looks like for me also is too difficult to understand
Anyway, are these screenshots from your browser?
I guess that the 1st image is the upgrade page shown twice plus the index in the back and the 2nd is your site new index page
Could be a browser cache or else I cannot understand how this can happen
Well, unless you have coded upgrade.html in such a way to show all this.
What happens if you visit directly upgrade.html?
 
Old 11-20-2009, 08:15 AM   #11
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Original Poster
Rep: Reputation: 15
Screen shots are from my browser, I use SnagIt.

If I go DIRECTLY to upgrade.html, it works perfect.

Please see atached txt file for upgrade.html, maybe something is wrong that I overlooked.
Attached Files
File Type: txt upgrade.txt (1.2 KB, 6 views)
 
Old 11-20-2009, 08:30 AM   #12
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,788

Rep: Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590
My fault. It's not the upgrade.html that you have to look, but the index page.
You should also try to visit the faulty page directly and see what you get
 
Old 11-20-2009, 08:32 AM   #13
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Original Poster
Rep: Reputation: 15
I didn't understand that, can you say that a little clearer with step by step instructions?
 
Old 11-20-2009, 08:54 AM   #14
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,788

Rep: Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590Reputation: 1590
I think that maybe I can see what happens:
From the upgrade.html, I see that you're using external http requests for the images in your page, so you get redirected to upgrade html
Try adding as another RewriteCond (changing domain.com accordingly):
Code:
RewriteCond %{HTTP_HOST} !^www.domain.com$ [OR]
RewriteCond %{REMOTE_HOST} !^23.27.254.134
RewriteCond %{REQUEST_URI} !^/upgrade.html$
RewriteRule ^(.*) http://%{HTTP_HOST}/upgrade.html [L]
and see what happens

Last edited by bathory; 11-20-2009 at 08:56 AM.
 
Old 11-20-2009, 08:58 AM   #15
comptech520
Member
 
Registered: Apr 2006
Posts: 31

Original Poster
Rep: Reputation: 15
Still the same thing
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
.htaccess question mlapl1 Linux - Newbie 1 06-05-2009 02:54 PM
.htaccess question Seventh Linux - Security 1 07-22-2006 11:31 PM
.htaccess question kidestranged Linux - Software 0 03-08-2005 11:57 AM
.htaccess question djthewombat Linux - General 1 10-21-2002 08:24 AM
htaccess question Legolas Linux - Security 0 08-24-2001 01:14 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:20 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration