The .htaccess works fine on the live server but here on my development system, it does not appear to be doing so. If I purposely enter an invalid address, it just gives the basic Apache error.
It is enabled in Apache2.conf with AccessFileName .htaccess but is there anything else that needs to be enabled to make it work? At one point it was working but many system updates later, I just noticed that it is not.
RewriteEngine On
AddDefaultCharset UTF-8
Options -Indexes Includes +FollowSymLinks
DirectoryIndex index.php
ErrorDocument 400 /messages/validate.php?error=400
ErrorDocument 401 /messages/validate.php?error=401
ErrorDocument 403 /messages/validate.php?error=403
ErrorDocument 404 /messages/validate.php?error=404
ErrorDocument 406 /messages/validate.php?error=406
ErrorDocument 408 /messages/validate.php?error=408
ErrorDocument 500 /messages/validate.php?error=500
<Files .htaccess,db_mysql.php,config.php,common.php>
Order Allow,Deny
Deny from all
</Files>
Related
How can i change the 404 Error Page with .htaccess.
Actually, i have an htaccess file that contains rewrite rules.
In brief,i want to customize 401, 402, 403, 404 and 405 error pages.
My reputation does not allow me to comment, so i have to answer.
Example:
Options +FollowSymlinks -MultiViews -Indexes
RewriteEngine On
#
# .htaccess content
#
ErrorDocument 403 403.php
ErrorDocument 404 /AnyDir/404.php
ErrorDocument 500 /OtherDir/500.php
my page frequently gives errors like forbidden access or internal server error, i think the problem its because my .htaccess file configuration, here it is :
<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
Options Indexes
ErrorDocument 400 ../errors/400.html
ErrorDocument 401 ../errors/401.html
ErrorDocument 403 ../errors/403.html
ErrorDocument 404 ../errors/404.html
ErrorDocument 500 ../errors/500.html
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.bedif\.net)(:80)? [NC]
RewriteRule ^(.*) http://bedif.net/$1 [R=301,L]
DirectoryIndex index.html
order deny,allow
deny from ../tools/
deny from ../lightbox/
deny from ../errors/
deny from ../images/
2 things:
deny from ../tools/ makes no sense at all, and all your deny from lines are causing a 500 error. The mod_auth docs say the syntax for this is:
Deny from all|host|env=[!]env-variable
Which means it can either be a "all", a host/IP, or an environmet variable. ../tools/ is none of them. You can't put paths in a Deny.
The ErrorDocument directive takes either a full URL, or an absolute path to a file. Anything else, apache assumes you're giving it a specific error message. This means, if you go to a file that doesn't exist, you'll get a 404 and the page will literally say:
../errors/404.html
as the page's message, and not the contents of the html file. Change those to absolute paths.
I'm using a whitelist on IP's, and as such I'd like to inform the user why this is so.
order deny, allow
deny from all
allow from 24.11.95.152
My IP whitelist in HTACCESS ^
Now, I set the ErrorDocument to /403
ErrorDocument 403 /403
and finally I rewrite /403 to uhoh.php
RewriteEngine On
RewriteRule ^403/?$ uhoh.php [NC]
However, I still get the typical error from LiteSpeed.
You can use ErrorDocument directly with the file you wish to use for custom message.
In your case would look like this:
ErrorDocument 403 /uhoh.php
From your example, it looks like you're trying to double redirect the error page which is not really needed.
i want to redirect to the error page if the page is not found. so i have add this code in .htaccess file.
# '404 Not Found' error
ErrorDocument 404 /index.php?p=error&code=404
but when i test it will not redirect to index.php file.
my whole .htaccess file code is here
#AuthName "Restricted Area"
#AuthType Basic
#AuthGroupFile /dev/null
#require valid-user
#<Files "/site/captcha/">
# Allow from all
#</Files>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
## File paths are relative to the Document Root (/)
# '400 Bad Request' error
ErrorDocument 400 /index.php?p=error&code=400
# '404 Not Found' error
ErrorDocument 404 /index.php?p=error&code=404
# '403 Forbidden' error
ErrorDocument 403 /index.php?p=error&code=403
# '401 Unauthorized' error
ErrorDocument 401 /index.php?p=error&code=401
# '500 Internal Server Error'
ErrorDocument 500 /index.php?p=error&code=500
############################# Pages ##########################################################
RewriteRule ^home/$ index.php [S=1]
RewriteRule ^home$ index.php [S=1]
</IfModule>
To start with -- move all ErrorDocument directives out of <IfModule mod_rewrite.c> -- there is no need at all for that.
Right now it tells Apache: "use ErrorDocument ONLY IF mod_rewrite is enabled".
If it does not work for you right now, then it is extremely likely that mod_rewrite is not actually enabled. But if you place them outside <IfModule mod_rewrite.c> block (just before it), then it should work (as long as .htaccess is recognised and processed by Apache):
#AuthName "Restricted Area"
#AuthType Basic
#AuthGroupFile /dev/null
#require valid-user
#<Files "/site/captcha/">
# Allow from all
#</Files>
Options +FollowSymLinks
# '400 Bad Request' error
ErrorDocument 400 /index.php?p=error&code=400
# '404 Not Found' error
ErrorDocument 404 /index.php?p=error&code=404
# '403 Forbidden' error
ErrorDocument 403 /index.php?p=error&code=403
# '401 Unauthorized' error
ErrorDocument 401 /index.php?p=error&code=401
# '500 Internal Server Error'
ErrorDocument 500 /index.php?p=error&code=500
<IfModule mod_rewrite.c>
RewriteEngine on
# Pages
RewriteRule ^home/?$ index.php [L]
</IfModule>
P.S.
I have also modified your rewrite rules: jointed them together into single rule.
How can I get the user to be redirected if their IP was matched on the deny of an IP address, e.g.
<Limit GET POST PUT>
order allow,deny
allow from all
deny from {removed IP address}
</Limit>
I need them to be redirected to a specific website when they are denied from accessing.
Needing help with this..
Setup a script to handle 403 errors by adding this line to your .htaccess:
ErrorDocument 403 /forbidden.php
Then handle the redirect in the script:
<?php
header('Location: http://google.com');
Or to keep it all in .htaccess you could do:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} 127.0.0.1
RewriteRule (.*) http://google.com [R]
Simple solution using only htaccess
ErrorDocument 403 https:///google.com
Order Allow,Deny
Allow from 127.0.0.0/8
Allow from x.x.x.x
Allow from y.y.y.y
Make sure to comment out the directives in welcome.conf, otherwise it will keep overriding your custom ErrorDocument directive.
After that, you can put your ErrorDocument directive in VirtualHost, Document directive or in your .htaccess https://httpd.apache.org/docs/2.4/custom-error.html
Like so:
ErrorDocument 403 <Local file/Remote URL>
And if this doesn't work, then you will have to look into your CORS rule