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 12-17-2011, 08:44 AM   #1
osmy
Member
 
Registered: Mar 2011
Posts: 58

Rep: Reputation: 0
Lightbulb htaccess configuration help


Hello, I want to create an htaccess file which allows specified ip(s) to show content on web-site, if ip is not listed than redirects it to another webpage url. I am trying to use this to building up my website. I will be able to create my website and view it while other users see under construction page. Here is what I am trying:

order deny,allow
deny from all
allow from 888.888.888.888

I got it but do not how to redirect un-listed ip's to an url or a subdomain.

Hope someone help me!
Thanks
 
Old 12-17-2011, 09:30 AM   #2
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
I found and tested, it works. If someone needs something like this here it is:
Edit url and Copy paste it to your .htaccess file

# redirect all visitors to alternate site but retain full access for you
ErrorDocument 403 http://www.xxx.com # non authorized ip's redirected to this url
Order deny,allow
Deny from all
Allow from xx.xx.xx.xx # allowed ip adress

Cheers
 
Old 12-17-2011, 09:31 AM   #3
wile_coyote
Member
 
Registered: Aug 2010
Location: Somewhere in NM USA
Distribution: Gentoo, Vector, Slackware , Arch
Posts: 47

Rep: Reputation: 3
Try looking herehttp://www.yolinux.com/TUTORIALS/ApacheRedirect.html most of the way down the page, hopefully it'll help you out.
 
Old 12-17-2011, 09:32 AM   #4
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
I found the solution, but thanks for your affort!
 
Old 12-19-2011, 05:53 PM   #5
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
Hey, I can't redirect a subdomain with using this htaccess configuration, any suggestions?

# redirect all visitors to alternate site but retain full access for you
ErrorDocument 403 http://www.xxx.com # non authorized ip's redirected to this url
Order deny,allow
Deny from all
Allow from xx.xx.xx.xx # allowed ip adress
 
Old 12-19-2011, 06:31 PM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,518

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
Hi,

If the .htaccess is in the server's docroot and the subdomain's docroot is a subdirectory of it, then it should work.
BTW as an alternative, you can use mod_rewrite:
Code:
RewriteEngine on

RewriteCond %{REMOTE_HOST} !^xx.xx.xx.xx
RewriteRule (.*) http://www.xxx.com [R=302]
Regards
 
Old 12-20-2011, 05:48 AM   #7
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
Hi bathory

I try yours I am getting this error:

This webpage has a redirect loop

I want to access web-site with my ip, and let all other visitors redirect to subdomain for example: comingsoon.xxx.com so when non-authorized ip visits xxx.com he will redirected to comingsoon.xxx.com

Hope this helps. Thanks
 
Old 12-20-2011, 06:04 AM   #8
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
Any suggestions?
I always get:
This webpage has a redirect loop

error
 
Old 12-20-2011, 06:28 AM   #9
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,518

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
You can add another condition to check the host requested:
Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^xxx.com$
RewriteCond %{REMOTE_HOST} !^xx.xx.xx.xx
RewriteRule (.*) http://comingsoon.xxx.com [R=302]
 
Old 12-20-2011, 06:40 AM   #10
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
Voila, it works! Thanks bathory!!!
 
Old 12-20-2011, 07:41 AM   #11
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
One last question,
when I entered xxx.com it redirects http://comingsoon.xxx.com without any problem
but
when I entered www.xxx.com it does not redirects http://comingsoon.xxx.com

www formatted url won't work, is there a solution to use www. too
 
Old 12-20-2011, 07:54 AM   #12
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
One last question,
when I entered xxx.com it redirects http://comingsoon.xxx.com without any problem
but
when I entered www.xxx.com it does not redirects http://comingsoon.xxx.com

www formatted url won't work, is there a solution to use www. too
 
Old 12-20-2011, 08:02 AM   #13
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 11,518

Rep: Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501Reputation: 1501
Yup
Code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^xxx.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.xxx.com$
RewriteCond %{REMOTE_HOST} !^xx.xx.xx.xx
RewriteRule (.*) http://comingsoon.xxx.com [R=302]
 
Old 12-20-2011, 08:05 AM   #14
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
Hey I found IT, no need to answer!

RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxx.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.xxx.com$
RewriteCond %{REMOTE_HOST} !^xx.xx.xx.xx
RewriteRule (.*) http://comingsoon.xxx.com [R=302]
 
Old 12-20-2011, 08:06 AM   #15
osmy
Member
 
Registered: Mar 2011
Posts: 58

Original Poster
Rep: Reputation: 0
I realise that you have already answered my question, thanks for support bathory!
 
  


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
Per Directory configuration in Lighttpd aka htaccess entz Linux - Software 3 08-18-2010 08:27 AM
.htaccess-any help fareen Linux - Networking 0 01-20-2006 03:05 PM
htaccess kuplo Linux - Newbie 4 12-16-2005 06:42 AM
.htaccess Lionheart008 Linux - Newbie 1 10-15-2004 03:15 PM
.htaccess axman Linux - Newbie 1 08-16-2001 06:36 AM


All times are GMT -5. The time now is 06:27 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