Sonjoy Datta
Sonjoy Datta

Reputation: 1388

How to rewrite htaccess 404

I am developing a raw PHP web application. But, I am facing problem when I use invalid words after url (just for check).

Current htaccess code:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ $1.php [NC,L]
ErrorDocument 404 https://example.com/404
Options -Indexes

For Example:

I need https://example.com/profile (without extension). Which is now working with the following htaccess code. When I hit https://example.com/profile/lllflfl (lllflfl is invalid words, just for check 404 error) it's goes to 404 error page. Which is also good. But, when I hit https://example.com/profile.php/lllflfl then my website still display current page (current page means https://example.com/profile this page). I think this need to redirect 404 page. What is your thoughts?

Thank you.

Upvotes: 1

Views: 382

Answers (2)

Mohammed Elhag
Mohammed Elhag

Reputation: 4302

If you don't want the suggestion by @starkeen which is very vital you could do this :

RewriteRule ^(.*)\.(php|html|htm)/.*$ - [L,R=404]

and let them treated as error requests.

Upvotes: 2

Nerdi.org
Nerdi.org

Reputation: 923

RewriteRule ^profile.php/.*$ /404pagehere.php [L]

Upvotes: 1

Related Questions