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

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]

Related

How do I prevent google web crawler from reading a single page as two different pages

I have a web page say example.com/blog/news.php which I used this code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
in the .htaccess file to hide the file extension. But google crawler reads example.com/blog/news.php and example.com/blog/news as two different pages. Please how do I prevent this, I tried to redirect the news.php page to news but it returned an error message saying to much redirect or something like that.
You can 301 redirect your .php URLs to the new (non-php ) format using the following rule and this way Google will only index your new URL.
Put the following right bellow RewriteEngine on and before your existing rules :
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^([^.]+)\.php$ /$1 [L,R=301]

How to fix my htaccess, it's redirecting my pages all to one index

I was on live chat with my domain support and they managed to delete the default htaccess file, now every url entered goes to my main index, what can I do to fix this?
Example:
domain: example.com
If I have a folder under example.com/folder
and go to it, the index for example.com shows instead of for that folder and if I put the path directly it stays in the browser but it shows the index for example.com always.
What can I write in my htaccess to fix this to how it used to be and keep mod rewrite enabled?
Edit: also, every time I've asked them to fix it or reset it to default they claim that it's a web development issue and not theirs. All they do is tell me to contact my developer.
hopefully, it works
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

How to redirect all html files in a domain to a specific webpage?

I have 2 bluehost accounts. One belongs to a former employee and the other is our companies new one. We have several domains in the old account, like chinafabrix.com and we want all domains to redirect to our new website vitasino.com. The thing is that we dont just want chinafabrix.com to redirect but also chinafabrix.com/index.html chinafabrix.com/whatever.html chinafabrix.com/blahah.html etc etc to redirect to vitasino.com (not vitasino.com/x.html but only vitasino.com)
Is there any way of doing this without writing a separate redirect in all the html files in the domain?
RewriteEngine on
RewriteRule ^(.*)$ http://www.vitasino.com/$1 [R=301,L]
or
RewriteEngine On
RewriteRule ^(.*)$ http://vitasino.com/ [R=301]
In the site root .htaccess of your old site you can place this single catch-all rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?chinafabrix\.com$ [NC]
RewriteRule ^(.+\.html)?$ http://vitasino.com/? [L,NC,R=301]

Shortten URL's with htaccess that works with Google indexing

Ok, let's explain first what I have in the server and in the htaccess file:
In the server I have the following files:
www.mydomain.com/provincias/madrid/town1.html
www.mydomain.com/provincias/madrid/town2.html
www.mydomain.com/provincias/madrid/town3.html
...
www.mydomain.com/provincias/barcelona/town1.html
www.mydomain.com/provincias/barcelona/town2.html
...
as you see, the folder 'provincias' is repeated in all urls, is necessary for get ordered the internal files but not for navigate and for users, for this reason I have added the following rule in the htaccess file that works fine:
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)\.html$ provincias/$1/$2\.html [L,NC]
so with this rule you can access, for example, the next url: www.mydomain.com/provincias/barcelona/town2.html with this other url that users see in the address bar of their browsers: www.mydomain.com/barcelona/town2.html because internally the htaccess redirect it to the real url with 'provincias'.
But I have a problem, I have seen that Google has indexed the technical and real url, the first one, with 'provincias' folder, and if you click on it people navigate watching that url in their address bar. How can I redirect the people and google traffic from www.mydomain.com/provincias/barcelona/town2.html to www.mydomain.com/barcelona/town2.html taking into consideration that internally the url without 'provincias' doesn't exist?
Try this rule in your .htaccess
#redirect real url to new one
RewriteCond %{THE_REQUEST} [A-Z]{3,}\ /+provincias/([^&\ ]+)/([^&\ ]+)\.html
RewriteRule ^ /%1/%2.html? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)\.html$ provincias/$1/$2\.html [L,NC]

.htaccess Redirect all users to subfolder EXCEPT for IP

I've tried countless combinations from forums, answers here on Stack Overflow, and blogs. I can't get this to work right.
I'd like to redirect all users to a subdirectory - "/const" - except for an IP that I deem worthy.
This is what I'm using so far:
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^91\.143\.253\.211
RewriteCond %{REQUEST_URI} !^/const/ [NC]
RewriteRule ^(.*)$ http://website.com/const/$1 [R=302,L]
And it redirects to the subfolder correctly, but it still redirects me, which is bad.
Little help?
You can use a Skip flag [s]. Here is an example with multiple IPs.
RewriteEngine on
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^91\.143\.253\.211$ [OR]
RewriteCond %{REMOTE_ADDR} ^8\.8\.8\.8$
RewriteRule .? - [S=1]
RewriteCond %{REQUEST_URI} !^const [NC]
RewriteRule ^(.*)$ /const/$1 [R=302,L]
Note
In the example before I had %{REQUEST_FILENAME}. This typically only works on server config files where the path to the filename itself is visible to the redirection script. Here I've changed it to %{REQUEST_URI} the part of the request that the browser can actually access.
The rule that you have is correct. When I add those to a blank htaccess file, I get redirected to http://website.com/const/ as expected unless I change the first condition to my actual IP. Some things you should check:
Make sure you've flushed your browser's cache. Although 302 redirects shouldn't be cached in such a way, better to flush it just in case.
Make sure you are actually making a request from the expected IP (i.e. ^91\.143\.253\.211$). You can test this by adding this rule to the top of your htaccess file:
RewriteRule ^foo$ http://foo.bar/IP/%{REMOTE_ADDR} [L,R]
And if you go to http://website.com/foo you should get redirected to a non-existing site but with your IP in the URL. If that IP doesn't match 91.143.253.211 then you need to change your condition to match the right IP.