Welcome to WebmasterWorld Guest from 54.196.238.210

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

dedicated IP to a specific page using HTACCESS

     

jinnguyen

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

6:15 am on Jun 25, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

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

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

7:51 am on Jun 25, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

jinnguyen

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

8:38 am on Jun 25, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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

jinnguyen

8:49 am on Jun 25, 2012 (gmt 0)



Got it g1smd!

;)

lucy24

8:57 am on Jun 25, 2012 (gmt 0)

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



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

9:10 am on Jun 25, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



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.
 

Featured Threads

Hot Threads This Week

Hot Threads This Month