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

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]

Related

Redirect from one website to another and keep directory

The blog section of a website moved from a subdomain to a directory of the main domain. I need to redirect all users visiting blog.site.com to site.com/blog/ and the directory someone enters should be kept when forwarding, e.g. blog.site.com/post/welcome should point to site.com/blog/post/welcome
I treid adding this to my .htaccess file which I placed in the subdomain's directory via FTP:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.herderzeitung.de$ [OR]
RewriteCond %{HTTP_HOST} ^www.blog.herderzeitung.de$
RewriteRule (.*)$ https://herderzeitung.de/blog/$1 [R=301,L]
However, this doesn't seem to be working. I was also wondering, what the most SEO friendly way is to achieve this (the site permanently moved to another domain).
Thanks in advance!
Try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.herderzeitung\.de$ [OR]
RewriteCond %{HTTP_HOST} ^www\.blog\.herderzeitung\.de$
RewriteRule ^/?(.*)$ https://herderzeitung.de/blog/$1 [R=302,L]
I've escaped the dots, and anchored&normalized the pattern. Also switched it to temporary redirects (302); once you know it works, then change it to 301 again for SEO reasons.
And yes, as far as i know 301s are the best method for retaining your search rankings and the like.
This seems to work:
RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$ https://herderzeitung.de/blog/$1 [L,R=301]
Thank you everyone!

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]

Need Help in my website IP Canonicalization .htaccess

i have searched the whole internet to find solution my website is www.hrxlevels.tk and ip address associated with website is this 31.170.163.33 and want the .htaccess for ip to redirect to domain
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hrxlevels.tk [NC]
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^31\.170\.163\.33
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301
RewriteBase /
and this code is not working for ip canonicalization but works great for url cononicalization please help please!
please use this detail and please write the .htaccess file for my website.
My webhost is 000webhost.com

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]

.htaccess redirect

Just wondering if someone can help me with the following issue.
I want to redirect my site to a subdomain, whishc simply displays a maintenace page, allowing me to work on the main site.
So I have the following code for my .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.co.uk$
RewriteRule ^/?$ "http\:\/\/maintenance\.domain\.co\.uk" [R=301,L]
However, I need to access the root domain to be able to view the work that I have done; however, I only want myself on my IP to be able to view that and the outside world is redirected to the subdomain which displays the maintenace page.
I would have thought that the following code:
RewriteCond %{REMOTE_HOST} !^00\.000\.00\.000
Would have allowed me to do that; however, I'm still being redirected to the sub domain and I wondered is someone could assist me further wth this.
Thanks
You'd be better of using %{REMOTE_ADDR}, I believe:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC]
RewriteCond %{REMOTE_ADDR} !=00.00.00.00
RewriteRule ^/?$ http://maintenance.domain.co.uk/ [R=301,L]