I am trying to use an htaccess redirect, and for some reason when I try to redirect the user, instead of going to page.html, it tries to go to page.htmlpage.htmlpage.htmlpage.html and it just keeps on repeating it. Anyone have any clue what I am going wrong?
Here is my htaccess file:
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName 2enetwork.x10hosting.com
Options All -Indexes
ErrorDocument 401 /error/401.html
ErrorDocument 403 /error/403.html
ErrorDocument 404 /error/404.html
ErrorDocument 500 /error/500.html
Redirect / http://2enetwork.tk/under_construction.html
#RewriteEngine On
#RewriteRule ^(.*)$ ./under_construction.html [L]
Oh, and also, it will give me a 403 error and underneath that it says and addition 302 error was found. If I comment the Redirect / http://2enetwork.tk/under_construction.html, it works fine. There is nothing wrong with the site, and I can see the under construction page fine.
Ok, I figured out why. When I sat there and tried to rediret my site, I redirected the whole site to uc.html (under_construction.html), and uc.html is included in the rest of the site, so it would then try to redirect to uc.html again, and again, and again in a never ending loop. So, my new question is, How do I prevent this from happening? Is there a way I can redirect my whole site minus uc.html?
Anything more complex than a brute force "go there" needs mod_rewrite.
This hasn't been tested, but...
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !under_construction\.html$
RewriteRule ^(.*)$ ./under_construction.html [L]
This RewriteCond line tells it to rewrite all requests except ones for files named under_construction.html*.
* Techinically, all files that end with the string "under_construction.html".
Related
I have a htaccess file with following code when trying to block an IP:
DirectoryIndex index.php index.html
ErrorDocument 404 /errors.php
Order Allow,Deny
Deny from 188.143.232.
Allow from all
Blocking my own IP works when browsing www.example.com, but it does not block for anything else (like www.example.com/index.php or www.example.com/home, ....). The htaccess is located in the same directory as index.php (httpdocs folder).
How can I get it to work?
You can also use a mod-rewrite based ip-blocking to block unwanted ip(s) :
RewriteEngine on
#--if client ip==188.143.232
RewriteCond %{REMOTE_ADDR} ^188\.143\.232
#--forbid the request
RewriteRule ^ - [F,L]
We've moved a site to another domain and setup the htacess as bellow, but how can i set a rule "if page dosnt exist - (ie 404 error) redirect to new site homepage." To be used as a fall back, if someone follows a broke url to our old site.
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.oldsite\.co\.uk)(:80)? [NC]
RewriteRule ^(.*) http://oldsite.co.uk/$1 [R=301,L]
Redirect permanent http://oldsite.co.uk http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/index.html http://newsite.co.uk
Redirect permanent http://oldsite.co.uk/contact-us.html http://newsite.co.uk/contact-us.html
Redirect permanent http://oldsite.co.uk/bespoke-furniture.html http://http://newsite.co.uk/bespoke-furniture.html
Redirect permanent http://oldsite.co.uk/about-us.html http://newsite.co.uk/about-us.html
Redirect permanent http://oldsite.co.uk/how.html http://newsite.co.uk/about-us.html
order deny,allow
You could simply use this.
ErrorDocument 404 http://newsite.co.uk
i need .htaccess code to redirect and ban ip's ,i mean if i try to load www.site.com with 123.456.789.101 ip address allow me, but if someone else try to load ,redirect them to other subdomain like sub.site.com , i write below code but dont work correctly.
<Limit GET POST PUT> Order Deny,Allow
Deny from all
Allow from 123.456.789.101
</Limit>
301 redirect / http://new.site.com
<Files otherpage.html>
Order Allow,Deny
Allow from all
</Files>
please help , Tank You
Replace your Limit block and 301 redirect with this:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.101$
RewriteRule ^(.*)$ http://new.site.com/$1 [L,R=301]
So that it's above your Files block (though I'm not sure why you'd need that)
I currently have 2 domains using the same httpdocs folder, what i need to do is to deny the access to the favicon when the request comes from one of my domains or simply redirect it to another favicon file.
I've been trying to solve this by editing the .htaccess file but i can't figure out how to make the RewriteRule to work.
Thank you very much
To deny access to the favicon.ico completely you can use a <Location> directive in your .htaccess file:
<Location /favicon.ico>
Order deny,allow
Deny from all
</Location>
If you wanted to redirect instead, you might do it this way:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^host1.domain.com$
RewriteRule ^favicon.ico /host1-favicon.ico
RewriteCond %{HTTP_HOST} ^host2.domain.com$
RewriteRule ^favicon.ico /host2-favicon.ico
I have got lots of ideas from google and stackoverflow- but none of those was exactly what i am looking for. here is scenario-
I have bought a hosting space from a provider. I had to provide a domain name(let abc.com) as the primary domain of that hosting space.
Then i have found that i have to put all the contents for that rimary domain(abc.com) into the document root directly. that is no directory like www/abc or www/abc.com.
Then I googled and found lots of .htaccess solution. I picked the following one-
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} abc.com
RewriteCond %{REQUEST_URI} !^/abc.com/(.*) [NC]
RewriteRule ^(.*)$ /abc.com/$1
I have just paste above lines at the end of the existing .htaccess file (default).
It was working fine. I have been using www/abc.com directory for my abc.com domain from then.
Recently I have added some subdomains (let xyz.abc.com) to my abc.com domain. But it is behaving strange with me. all subdomains are looking for its contents from abc.com/subdomain (eg. abc.com/xyz.abc.com)
This time i am getting no solution over google (i may missed it).
Someone help me please- i am in bad shape.
EDITED:
Following lines were in WebRoot .htaccess from the beginning. After that I have added additional lines as mentioned above(3,4)
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName abc.com
AuthUserFile /home/abc/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/abc/public_html/_vti_pvt/service.grp\
EDITED AGAIN:
There are some other domains(except the main domain abc.com) in the same hosting space. Those domains have some working sub-domains. But sub-domain of main domain is not working as i explained above.
Change
RewriteCond %{HTTP_HOST} abc.com
to
RewriteCond %{HTTP_HOST} ^abc.com$
Now the rules do not match your subdomains anymore.
Update
# catch www.abc.com and abc.com (and wwwwwwwwwww.abc.com)
RewriteCond %{HTTP_HOST} ^(w+\.)?abc\.com$