简体   繁体   中英

.htaccess not redirecting to error page

I'd created .htaccess file to remove canonical issue with my site.
Here's the code:

<Files ~ "^\.(htaccess|htpasswd)$">
deny from all
</Files>
ErrorDocument 404 http://www.reddyclasses.com/error.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(reddyclasses\.com)(:80)? [NC]
RewriteRule ^(.*) http://www.reddyclasses.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ /%1 [R=301,L]

DirectoryIndex index.php index.html      
order deny,allow

Is this code is correct? Also, my site is not redirecting to error page if I do enter a wrong url like http://reddyclasses.com/err . Why?

it doesn't redirect because you redirect all traffic to index.php so http://reddyclasses.com/err does exist. You need to trigger 404 error from PHP itself in this case..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM