homepage Welcome to WebmasterWorld Guest from 50.16.112.199
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
dedicated IP to a specific page using HTACCESS
jinnguyen



 
Msg#: 4469084 posted 5:10 am on Jun 25, 2012 (gmt 0)

Hi,

I couldn't find the solution to this problem any where on the net. How do you redirect a dedicated IP to a specific page, with exact match for that dedicated IP only? The code below seems to be working, but it will redirect (not really a redirect but actually return a 200 OK, which is what I want)any random queries to the specific page. For example, 123.456.789.#*$!/some_random_queries will redirect to the specific page too. I need those random queries to be return as 404 not found.


RewriteCond %{HTTP_HOST} ^123\.456\.789\.#*$!
RewriteCond %{REQUEST_URI} !^/no_website_here\.html$ [NC]
RewriteRule ^(.*) /no_website_here.html [L]



Thanks for helping,

 

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4469084 posted 6:15 am on Jun 25, 2012 (gmt 0)

The above code is for an internal rewrite.

(.*) says "do this for all requested folders and pages".

You said "random queries", but as the example did not contain a question mark I assume you mean "random paths".

You'll need two rules, both with the (.*) replaced by something else (assume !. for one and .+ for the other).

The rule target for !. will point to a file that exists and that content will be shown with 200 OK status. The rule target for .+ will point to a filepath that does not exist and that will trigger the 404 response.

Both of these rules will be at the start of your htaccess file.

jinnguyen



 
Msg#: 4469084 posted 6:57 am on Jun 25, 2012 (gmt 0)

Hi g1smd,

Yes, I guess I wasn't very clear on the question, I believe like you said "random paths." A request directly on my dedicated IP (exact match) will return a page that I will put something like "no website configured at this address." and for any thing else or random paths like 123.456.789.000/any_paths will just simply return 404s. The reason I want to do this is because some spammers keep pointing their sites to my dedicated IPs which cause their site to show up in search, and my real sites were vanished. I've tried to redirect 301 from IP to the domain name, but look like google just ignored. So this time I want to block the IPs for good.

So, how do I actually write those 2 extra rules with !. and .+ like you said? or modifying the code that I posted above? Sorry, I'm not very good at writing htaccess rules at all.

Thanks,

jinnguyen



 
Msg#: 4469084 posted 7:34 am on Jun 25, 2012 (gmt 0)

Update:

I messed around with htaccess code with help from the 2 extra rules !. and .+ you gave out earlier, and somehow it works! The codes look funny, but they just simply work. LOL


RewriteCond %{HTTP_HOST} ^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !^/no_website_here\.html$ [NC]
RewriteRule !. /no_website_here.html [L]

RewriteCond %{HTTP_HOST} ^123\.456\.789\.000
RewriteCond %{REQUEST_URI} !^/no_website_here\.html$ [NC]
RewriteRule .+ [R=404,L]


Thank you so much g1smd, you're the Best!

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4469084 posted 7:51 am on Jun 25, 2012 (gmt 0)

The second ruleset has syntax errors.
It should point to /does_not_exist where /does_not_exist does not exist.

jinnguyen



 
Msg#: 4469084 posted 8:31 am on Jun 25, 2012 (gmt 0)

Hi g1smd,

You're right, no wonder why I have a feeling that the codes I wrote look funny, even though it worked. It fixed and all good now after a long day.

Big Thanks again,

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4469084 posted 8:38 am on Jun 25, 2012 (gmt 0)

Apart from change of pattern (!. and .+) and change of filename (in two places each), they should be identical.

jinnguyen



 
Msg#: 4469084 posted 8:49 am on Jun 25, 2012 (gmt 0)

Got it g1smd!

;)

lucy24

WebmasterWorld Senior Member lucy24 us a WebmasterWorld Top Contributor of All Time Top Contributors Of The Month



 
Msg#: 4469084 posted 8:57 am on Jun 25, 2012 (gmt 0)

RewriteCond %{REQUEST_URI} !^/no_website_here\.html$ [NC]
RewriteRule !. /no_website_here.html [L]

Is
%{REQUEST_URI} !blahblah
a better approach than a RewriteCond looking at %{THE_REQUEST} ?

Oh, and it shouldn't start with ^/ should it?

g1smd

WebmasterWorld Senior Member g1smd us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 4469084 posted 9:10 am on Jun 25, 2012 (gmt 0)

REQUEST_URI is the full path, starting with ^/ even in htaccess context. Confuses me too. The way I remember it is that REQUEST_URI will not be blank when root is requested.

The RewriteCond here is saying "don't rewrite if already rewritten". It's a different scenario than the "redirect if this is an external request" you're thinking about.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved