简体   繁体   中英

How to redirect url to 404 page using htaccess?

When i am hitting https://mobilecoderz.com/contactffdd then it is returning 404 error page.

Which is absolutely working fine.

When i am hitting https://mobilecoderz.com/contact then it is returning Contact page.

Which is absolutely working fine.

But when i am hitting https://mobilecoderz.com/contact/adfadf then it is also returning contact page.

But it should return 404 error page. How can i achieve this using htaccess?

You can use these 2 lines at the top of your .htaccess:

DirectoryIndex index.html
ErrorDocument 404 http://yoururl

DirectoryIndex will make yoururl load yoururl/index.html by default and use of http:// in ErrorDocument will make it redirect to new URL.

OR

RedirectMatch 404 ^/abc/.*$

OR

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subfolder/404.php [L]

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