简体   繁体   中英

What is the proper .htaccess for blocking another website assigned to my dedicated IP

Here is my scenario: I have a website, that I own, and another website, which someone I don't know owns, is also assigned to that same IP address. When I view their website it is basically displaying all of the content from my website. This URL is #1 in certain keywords I'm using any my website is several pages deep in google. I can also log into the administrator portion of the website through the other URL that I don't own, which worries me from a liability stand point. I contacted my hosting provider and after about an hour and nothing to show for it here I am.

What I want to do is block the other website in .htaccess OR completely redirect all pages from that URL to my URL...

What is the best redirect method or code in this instance?

What I currently have still in my .htaccess allows the index page to be loaded on the remote website but all of the images and css loaded by that index page respond with a 403 forbidden. Problem with that is it is still loading my index page's meta description, keywords, html, and styles which is messing with my search engine optimization attempts.

I want the index page to not even load resulting in a forbidden error or a complete redirect including the base index page.

I also want to redirect any traffic that doesn't include the www before my domain to the www version and not result in a redirection loop.

Any help is greatly appreciated.

RewriteCond %{HTTP_REFERER} otherdomain\.com [NC]
RewriteRule .* - [F]
RewriteCond %{HTTP_HOST} ^otherdomain\.com [NC]
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ http://www\.mydomain\.com [R=301,L]

Use this code:

# block other domain
RewriteCond %{HTTP_HOST} ^(www\.)?otherdomain\.com$ [NC]
RewriteRule ^ - [F]

# put www before host name
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM