Redirect domain to 404 generic page - .htaccess

I have my website (a.com). Another person is pointing your domain (b.com) to my server. That is wrong.
Is it possible to redirect all traffic that comes from b.com for a generic 404 page? think this is possible with a file htaccess
Thanks you!
Edit
i can do this?
RewriteEngine On
RewriteRule ^(.*)$ http://www.b.com/$1 [R=404,L]
or
RewriteCond %{HTTP_HOST} ^www.b.com [nocase]
RedirectMatch 404 ^(.*)

You could do something like this:
UPDATE
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^domainb\.com$ [NC]
RewriteRule .* - [R=404]
You could also try a general forbidden error, like this:
order allow,deny
deny from b.com
allow from all

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERER} b\.com [NC]
RewriteRule ^ /404.html [R=404,L]
This will check if traffic is coming from b.com and if yes then it will redirect all the requests to a generic 404.html page.

How I did it was to put this code in the htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/index.html$
RewriteCond %{REQUEST_URI} !\.(gif|jpe?g|png|css|js)$
RewriteRule .* /index.html [L,R=302]
</IfModule>
Which send the request to the index.html file. Then use the refresh function in html to redirect the file to the desired domain:
index.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
<META http-equiv="refresh" content="0;URL=https://www.mydomain.co.uk/">
</head>
<body>
</body>
</html>

Related

Redirecting to another page - htaccess

I'd like to redirect the user to a page named test.php when he types the url of my site (example www.domain.com).
Pratically by typing www.domain.com the browser should show www.domain.com/test.php
At index.html or index.php, you could add meta refresh tag like this :
<meta http-equiv="refresh" content="5;www.domain.com/test.php" />
If you use index.php, the syntax would be like this:
echo '<meta http-equiv="refresh" content="5;www.domain.com/test.php" />';
Add http:// at the url if You want to redirect to another domain.
In top of your .htaccess file try this rules (except files and directories rewrite anything www/non www to example.com/test.php)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule (.*) http://example.com/test.php [L]
</IfModule>

Specific url redirect using .htaccess

I have this domain "www.mydomain.com/great/redirect"
I want to redirect it to "www.redirect.com/great/redirect"
using .htaccess so how can I do that?
Right now I am doing that using html
<meta http-equiv="refresh" content="0;url=http://redirect.com/great/redirect" />
in location of "www.mydomain.com/great/redirect" file.
Inside site root .htaccess of www.mydomain.com you can use this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain\.com$ [NC]
RewriteRule ^great/redirect/?$ http://redirect.com%{REQUEST_URI} [L,NC,R=301]

htaccess block direct access to specific file extensions with exceptions

I am trying to prevent users from accessing any files or directory directly except from my index.php using this htaccess:
Options -Indexes
RewriteEngine on
RewriteCond %{HTTP_REFERER} !^http://(www\.)?REMOVEDLINK [NC]
RewriteCond %{HTTP_REFERER} !^http://(www\.)?REMOVEDLINK.*$ [NC]
RewriteRule \.(gif|jpg|png|js|css)$ - [F]
ErrorDocument 403 http://REMOVEDLINK/404.html
ErrorDocument 404 http://REMOVEDLINK/404.html
I just used another htaccess within my php includes folder:
deny from all
Everything works fine except for the fact that it prevents my favicon from being displayed. Code from my index.php:
<link rel="shortcut icon" href="img/favicon.png" type="image/x-icon" />
How can I allow access for the favicon to be displayed?
Just below RewriteEngine On line include this rule to allow access to favicon:
RewriteRule img/favicon\.png$ - [NC,L]

Redirect with htaccess should not access some pages

I have 3 pages:
index.html
about.html
contact.html
I need to create an htaccess that redirects to home (index.html) if the visitor NOT go to one of those 3 pages.
Example:
If I go to page: asdf.html then I get redirected to index.html
But if income contact.html shows me that page.
¿How I can do?
Thank you.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/(index|about|contact)\.html [NC]
RewriteRule ^(?!.+?\.(?:jpe?g|gif|bmp|png|css|js)$).*$ /index.html [L,R,NC]

404 for simple redirect to /filename.html

I want to redirect to a certain html file in root when the user enters the domain.com. Simple as that. Get an 404.
RewriteRule .* /intro.html [NC,L]
Any ideas?
I have tried this in already:
<base href="/">
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^$ /intro.html [L]

Resources