ErrorDocument disbales .htaccess file - .htaccess

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.

Related

.htaccess to not affect subdirectories

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?

redirect 404 page using htaccess

I want to redirect some page on 404 page. How may I achieve it using htaccess file.
http://wowriters.com/author/admin/feed/
http://wowriters.com/reflective-portfolio/essay-writing-service
http://wowriters.com/reflective-portfolio/dissertation-service
http://wowriters.com/samples/essay-writing-service
http://wowriters.com/samples/uae
http://wowriters.com/worlds-biggest-beverages/coursework-help-service
http://wowriters.com/worlds-biggest-beverages/buy-essays
Above links should be gone on 404 page.
Kindly help me.
Thanks in advance.
You can use this rule as your topmost rule:
RewriteEngine On
RewriteCond %{REQUEST_URI} /author/admin/feed/ [NC,OR]
RewriteCond %{REQUEST_URI} /reflective-portfolio/(essay-writing|dissertation)-service [NC,OR]
RewriteCond %{REQUEST_URI} /samples/(uae|essay-writing-service) [NC,OR]
RewriteCond %{REQUEST_URI} worlds-biggest-beverages/(buy-essays|coursework-help-service) [NC]
RewriteRule ^ - [L,R=404]
ErrorDocument 404 http://wowriters.com/author/admin/feed/
ErrorDocument 404 http://wowriters.com/reflective-portfolio/essay-writing-service
ErrorDocument 404 http://wowriters.com/reflective-portfolio/dissertation-service
ErrorDocument 404 http://wowriters.com/samples/essay-writing-service
ErrorDocument 404 http://wowriters.com/samples/uae
ErrorDocument 404 http://wowriters.com/worlds-biggest-beverages/coursework-help-service
ErrorDocument 404 http://wowriters.com/worlds-biggest-beverages/buy-essays
All the page not found pages will display the links.

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'/>"

Url mod_rewrite remove consequtive trailing slashes on clean urls

Hello I would like to remove any trailing slashes from my clean urls so far my htaccess has the following code:
#php_flag display_startup_errors on
#php_flag display_errors on
#php_flag html_errors on
RewriteEngine on
<IfModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl|jpg|png|gif)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>
Options -Indexes
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)(.*)$ /index.php?page=$1&request=$2
#GAMW TON OHANAH
RedirectMatch 301 ^/component/(.*)$ http://www . evented . gr
ErrorDocument 404 /error.php?e=404
ErrorDocument 400 /error.php?e=400
ErrorDocument 401 /error.php?e=401
ErrorDocument 403 /error.php?e=403
ErrorDocument 405 /error.php?e=405
ErrorDocument 408 /error.php?e=408
ErrorDocument 410 /error.php?e=410
ErrorDocument 411 /error.php?e=411
ErrorDocument 412 /error.php?e=412
ErrorDocument 413 /error.php?e=413
ErrorDocument 414 /error.php?e=414
ErrorDocument 415 /error.php?e=415
ErrorDocument 500 /error.php?e=500
ErrorDocument 501 /error.php?e=501
ErrorDocument 502 /error.php?e=502
ErrorDocument 503 /error.php?e=503
ErrorDocument 506 /error.php?e=506
You may observe the strange behaviour if you like by visiting www . evented . gr
PS. I want consequtive slashes that have nothing in between to be replaced with 0 slash
for example www.domain.com////// to www.domain.com
or www.domain.com/events////// to www.domain.com/events
I have tryed the following but with no luck
RewriteCond %{REQUEST_URI} ^(.*?)(?:/){2,}$
RewriteRule . $1/ [R=301,L]
and
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
You can't do this with mod_rewrite. By the time your rules get applied, apache has already normalized the URI, all duplicate slashes are removed. If you make a request for:
http://www.evented.gr//////a////////b/////c/////d///////
The URI that mod_rewrite sees is this:
/a/b/c/d/
You'll have to come up with a different solution. The best thing to do is to fix this at the source, don't deploy with URLs that have duplicate slashes in the first place.

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