LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 07-07-2017, 06:45 AM   #1
gaurvrishi
Member
 
Registered: Apr 2012
Posts: 62

Rep: Reputation: Disabled
Apache rewrite rule


Hi,

I want to write apache rewrite rule which will allow only one IP address and not use SSL for that IP address.

Currently i am using below rewrite code but this is not working.

RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{REMOTE_ADDR} !^1\.2\.3\.4$
RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]


This is not working in my case.

Last edited by gaurvrishi; 07-07-2017 at 11:14 AM.
 
Old 07-07-2017, 12:29 PM   #2
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,

If I understand correctly what you're trying to do, then you can give a 403 error if the client is not 1.2.3.4 and use https if it is:
Code:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^1.2.3.4$
RewriteRule (.*) - [F]
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{SERVER_NAME}$1 [R,L]
Regards
 
Old 07-07-2017, 01:12 PM   #3
gaurvrishi
Member
 
Registered: Apr 2012
Posts: 62

Original Poster
Rep: Reputation: Disabled
My usecase is that we have two server and in one server we have configured ssl and in other server I.e apache jon ask server
Which is rubbing on port 80.
I want that if a request is coming from 1.2.3.4 IP address that we will served from non ssl port.
 
Old 07-07-2017, 04:25 PM   #4
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
I want that if a request is coming from 1.2.3.4 IP address that we will served from non ssl port.
If this is the only requirement, you need to do your rewrite in the ssl (apache?) server:
Code:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^1.2.3.4$
RewriteRule (.*) http://%{SERVER_NAME}$1 [R,L]
 
Old 07-08-2017, 01:56 AM   #5
gaurvrishi
Member
 
Registered: Apr 2012
Posts: 62

Original Poster
Rep: Reputation: Disabled
Thanks for your help. Could you please confirm if in future if i want to write such rewrite code then is there any online site for writing these code.
 
Old 07-08-2017, 03:26 AM   #6
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Hi,
Quote:
Originally Posted by gaurvrishi View Post
Thanks for your help. Could you please confirm if in future if i want to write such rewrite code then is there any online site for writing these code.
There are some online mod_rewrite generators, but I've never used any of them, so I cannot tell how well they perform.
Use your favorite search engine to find and test them

Regards
 
Old 07-12-2017, 07:15 AM   #7
gaurvrishi
Member
 
Registered: Apr 2012
Posts: 62

Original Poster
Rep: Reputation: Disabled
Hi,

I am trying to write one apache rewrite code but don't know the exact code.

My requirement is if that if someone hit my particular link to access it without authorization it will redirect request to any other link. For example:

http://abc.com/hub/pdffolder/.pdf to http://abc.com/bin/servive/sendcode?...pdffolder/.pdf link

In this folder pdffolder it contain any write like .txt .pdf etc http://abc.com/hub/pdffolder/.pdf
 
Old 07-12-2017, 12:57 PM   #8
bathory
LQ Guru
 
Registered: Jun 2004
Location: Piraeus
Distribution: Slackware
Posts: 13,163
Blog Entries: 1

Rep: Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032Reputation: 2032
Quote:
My requirement is if that if someone hit my particular link to access it without authorization it will redirect request to any other link. For example:

http://abc.com/hub/pdffolder/.pdf to http://abc.com/bin/servive/sendcode?...pdffolder/.pdf link
If someone tries to hit a URL without the authorization needed, he will get a 401 error.
What you can do, is to redirect the 401 response to the URL you want. E.g. add a .htaccess in /hub/pdffolder containing:
Code:
ErrorDocument 401 /bin/servive/sendcode?=uri/hub/pdffolder/.pdf
 
  


Reply

Tags
apache 2.4.2, rewriterule



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
[SOLVED] rewrite rule in apache mohitvad Linux - Newbie 3 09-14-2012 03:18 PM
[SOLVED] rewrite rule for apache linux_kung_fu Linux - General 2 07-04-2012 10:35 AM
apache rewrite rule sunlinux Linux - Newbie 5 11-14-2011 07:06 AM
apache rewrite rule sunlinux Linux - Newbie 10 11-11-2011 05:01 AM
apache rewrite rule sunlinux Linux - Server 2 09-25-2011 02:03 PM

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

All times are GMT -5. The time now is 03:57 PM.

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
Open Source Consulting | Domain Registration