LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Apache rewrite rule (https://www.linuxquestions.org/questions/linux-newbie-8/apache-rewrite-rule-4175609370/)

gaurvrishi 07-07-2017 06:45 AM

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.

bathory 07-07-2017 12:29 PM

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

gaurvrishi 07-07-2017 01:12 PM

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.

bathory 07-07-2017 04:25 PM

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]


gaurvrishi 07-08-2017 01:56 AM

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.

bathory 07-08-2017 03:26 AM

Hi,
Quote:

Originally Posted by gaurvrishi (Post 5732295)
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

gaurvrishi 07-12-2017 07:15 AM

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

bathory 07-12-2017 12:57 PM

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


All times are GMT -5. The time now is 11:00 AM.