.htaccess to not affect subdirectories - .htaccess

Need the .htaccess in root not to affect my subdirs.
My .htaccess looks mainly like this:
<Limit GET POST>
order allow,deny
Deny from 12.34.56.78.9
Deny from 12.34.56.78.0
allow from all
</Limit>
DirectoryIndex index.php
ErrorDocument 400 /400.html
ErrorDocument 401 /401.html
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
ErrorDocument 500 /500.html
ErrorDocument 500 /500.html
RewriteBase /
Ready to make another .htaccess in subdir but what to put in there?

Related

ErrorDocument disbales .htaccess file

If i add ErrorDocument directive to the .htaccess file , everything stops working . Do now know where is my mistake. Then i remove ErrorDocument directive, everything again works.
I have tried to use path relative to document root, or full url.
I also tried to make a separate folder in document root /err/errMsg.php and refer to it ErrorDocument 100 http://localhost/domainname.biz/err/errMsg.php , nevertheless, it would be better to be redirected topublic/index.php/err/err action.
My document root is :
DOCUMENT_ROOT /home/name/public_html/domainname.biz on server
DOCUMENT_ROOT ...../apache2/htdocs on localhost
.htaccess file for localhost :
ErrorDocument 100 /domainname.biz/public/index.php/err/err
#i also used ErrorDocument 100 http://localhost/domainname.biz/public/index.php/err/err
ErrorDocument 101 /domainname.biz/public/index.php/err/err
ErrorDocument 102 /domainname.biz/public/index.php/err/err
ErrorDocument 200 /domainname.biz/public/index.php/err/err
ErrorDocument 201 /domainname.biz/public/index.php/err/err
ErrorDocument 202 /domainname.biz/public/index.php/err/err
ErrorDocument 203 /domainname.biz/public/index.php/err/err
ErrorDocument 204 /domainname.biz/public/index.php/err/err
ErrorDocument 205 /domainname.biz/public/index.php/err/err
ErrorDocument 206 /domainname.biz/public/index.php/err/err
ErrorDocument 207 /domainname.biz/public/index.php/err/err
ErrorDocument 226 /domainname.biz/public/index.php/err/err
ErrorDocument 300 /domainname.biz/public/index.php/err/err
ErrorDocument 301 /domainname.biz/public/index.php/err/err
ErrorDocument 302 /domainname.biz/public/index.php/err/err
ErrorDocument 303 /domainname.biz/public/index.php/err/err
ErrorDocument 304 /domainname.biz/public/index.php/err/err
ErrorDocument 305 /domainname.biz/public/index.php/err/err
ErrorDocument 306 /domainname.biz/public/index.php/err/err
ErrorDocument 307 /domainname.biz/public/index.php/err/err
ErrorDocument 400 /domainname.biz/public/index.php/err/err
ErrorDocument 401 /domainname.biz/public/index.php/err/err
ErrorDocument 402 /domainname.biz/public/index.php/err/err
ErrorDocument 403 /domainname.biz/public/index.php/err/err
ErrorDocument 404 /domainname.biz/public/index.php/err/err
ErrorDocument 405 /domainname.biz/public/index.php/err/err
ErrorDocument 406 /domainname.biz/public/index.php/err/err
ErrorDocument 407 /domainname.biz/public/index.php/err/err
ErrorDocument 408 /domainname.biz/public/index.php/err/err
ErrorDocument 409 /domainname.biz/public/index.php/err/err
ErrorDocument 410 /domainname.biz/public/index.php/err/err
ErrorDocument 411 /domainname.biz/public/index.php/err/err
ErrorDocument 412 /domainname.biz/public/index.php/err/err
ErrorDocument 413 /domainname.biz/public/index.php/err/err
ErrorDocument 414 /domainname.biz/public/index.php/err/err
ErrorDocument 415 /domainname.biz/public/index.php/err/err
ErrorDocument 416 /domainname.biz/public/index.php/err/err
ErrorDocument 417 /domainname.biz/public/index.php/err/err
ErrorDocument 422 /domainname.biz/public/index.php/err/err
ErrorDocument 423 /domainname.biz/public/index.php/err/err
ErrorDocument 424 /domainname.biz/public/index.php/err/err
ErrorDocument 426 /domainname.biz/public/index.php/err/err
ErrorDocument 500 /domainname.biz/public/index.php/err/err
ErrorDocument 501 /domainname.biz/public/index.php/err/err
ErrorDocument 502 /domainname.biz/public/index.php/err/err
ErrorDocument 503 /domainname.biz/public/index.php/err/err
ErrorDocument 504 /domainname.biz/public/index.php/err/err
ErrorDocument 505 /domainname.biz/public/index.php/err/err
ErrorDocument 506 /domainname.biz/public/index.php/err/err
ErrorDocument 507 /domainname.biz/public/index.php/err/err
ErrorDocument 510 /domainname.biz/public/index.php/err/err
Options -MultiViews
Options -Indexes
Options +FollowSymlinks
# +FollowSymLinks must be enabled for any rules to work, this is a security requirement of the rewrite engine.
# Normally it's enabled in the root and you shouldn't have to add it, but it doesn't hurt to do so,
# Although highly unlikely, your host may have +FollowSymLinks enabled at the root level,
# yet disallow its addition in .htaccess; in which case, adding +FollowSymLinks will break your setup
# (probably a 500 error), so just remove it, and your rules should work fine.
RewriteEngine on
RewriteBase /
IndexIgnore *
RewriteCond %{HTTP_HOST} ^domainname\.biz [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^www.domainname\.biz [NC]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{ENV:REQUEST_FILENAME} !-d
RewriteCond %{ENV:REQUEST_FILENAME} !-f
RewriteCond %{ENV:REQUEST_FILENAME} !-l
RewriteRule ^index.php?(.+)$ index.php?url=$1 [QSA,L]
.htaccess file on server is the same, but i start from another document root
ErrorDocument 100 /public/index.php/err/err
#or https://www.domainname.biz/public/index.php/err/err
Not sure why do you have so many ErrorDocument lines in your .htaccess:
At the minimum remove the line for unsupported response code 306 to avoid 500 internal error on your website.
You should also remove handled for response code 200 as that is good status.

SImple way to redirect 403 and 404 errors to the main page htaccess

As the title says is there any easy way to redirect every forbidden error and page not found to my main page index.php?
Here is my htaccess don't think it will be of any use but here it is:
ErrorDocument 404 /leaguenotes/administration/cms/new_patch
ErrorDocument 403 /leaguenotes/administration/cms/new_patch
Options ALL -Indexes
RewriteEngine On
RewriteRule ^([0-9/.]+)$ index.php?Patch_No=$1 [NC,L]
RewriteRule ^([0-9/.]+)&([0-9a-zA-Z_-]+)$ index.php?Patch_No=$1&tab=$2 [NC,L]
RewriteRule ^patches php/patches.php [NC,L]
RewriteRule ^([0-9a-zA-Z_-]+)$ index.php?Champion=$1 [NC,L]
You can add these 2 lines on top of your .htaccess:
ErrorDocument 404 /
ErrorDocument 403 /
This will redirect every 403 and 404 errors to your home page.
You can try this on top of your .htaccess file
ErrorDocument 403 "<meta http-equiv='refresh' content='0; url=your_redirect_page.html'/>"

Mask 404 page URL with .htaccess

I've setup a 404 ErrorDocument handler in my htaccess file, and it works fine. However, the address bar reflects the filename of that file. I'd like to use mod_rewrite to mask the actual filename and replace it with something else while still actually displaying the file.
Here's my current htaccess file:
RewriteEngine On
Options +FollowSymlinks
Options All -Indexes
ErrorDocument 404 /404.php
RewriteRule ^404.php$ /error/404 [L]
Figured it out on my own... Rather than using the 404.php file in the ErrorDocument handler, I used the fake url, then added a rewrite rule to rewrite the fake url to the 404.php file (but without redirect).
RewriteEngine On
Options +FollowSymlinks
Options All -Indexes
ErrorDocument 404 /error/404
RewriteRule ^error/404$ /404.php [L]

Allow,Deny from .htaccess

I have a small problem trying to add the option Allow,Deny in my .htaccess
<Limit GET POST PUT>
order deny,allow
deny from all
allow from 192.168.10.100
allow from 192.168.10.200
</Limit>
Options All -Indexes
<IfModule mod_php5.c>
php_flag engine 0
</IfModule>
# AddHandler cgi-script .php .pl .py .jsp .asp .htm .shtml .sh .cgi
Options -ExecCGI
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
############################################
## never rewrite for existing files
RewriteCond %{REQUEST_FILENAME} !-f
############################################
## rewrite everything else to index.php
RewriteRule .* ../get.php [L]
</IfModule>
I cannot get in in the folder where is this .htaccess, the ip address is correct, if i keep only
<Limit GET POST PUT>
order deny,allow
deny from all
allow from 192.168.10.100
allow from 192.168.10.200
</Limit>
I can get in to the folder. but if i put together is not working anymore.
Any help is appreciated.

Google adds forward slash followed by other file to the search result

When I search my website on Google it used to add forwarding slash after URL, which I was able to figure out with great stackoverflow forum but I've seen a new problem, where it not only added forwarding slash after url but also a file name following it, see below what it looks like.
www.caeoutsourcingservices.com/aboutus.php/aboutus.php
www.caeoutsourcingservices.com/contactus.php/aboutus.php
Current URL of above are:
www.caeoutsourcingservices.com/aboutus.php
www.caeoutsourcingservices.com/contactus.php
I have some results with only forwarding flash added after URL like below for same site
www.caeoutsourcingservices.com/aboutus.php/
How do I resolve both problems :
adding slash and other random file name in url
adding slash after url.
my .htaccess looks like below.
RewriteEngine on
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} !^www\.caeoutsourcingservices.com [NC]
RewriteRule ^(.*) http://www.caeoutsourcingservices.com/$1 [L,R=301]
ErrorDocument 400 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 401 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 402 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 403 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 404 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 405 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 406 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 407 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 408 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 409 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 410 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 411 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 412 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 413 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 414 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 415 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 500 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 501 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 502 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 503 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 504 http://www.caeoutsourcingservices.com/sitemap.php
ErrorDocument 505 http://www.caeoutsourcingservices.com/sitemap.php
Thanks
Manoj Soni

Resources