简体   繁体   English

如何重写htaccess 404

[英]How to rewrite htaccess 404

I am developing a raw PHP web application. 我正在开发一个原始的PHP Web应用程序。 But, I am facing problem when I use invalid words after url (just for check). 但是,当我在url之后使用无效的单词(仅用于检查)时,我遇到了问题。

Current htaccess code: 目前的htaccess代码:

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). 我需要https://example.com/profile (没有扩展名)。 Which is now working with the following htaccess code. 现在正在使用以下htaccess代码。 When I hit https://example.com/profile/lllflfl ( lllflfl is invalid words, just for check 404 error) it's goes to 404 error page. 当我打https://example.com/profile/lllflfllllflfl是无效的话,只是为了检查404错误),这是进入404错误页面。 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). 但是,当我点击https://example.com/profile.php/lllflfl时,我的网站仍显示当前页面(当前页面表示https://example.com/profile此页面)。 I think this need to redirect 404 page. 我认为这需要重定向404页面。 What is your thoughts? 你有什么想法?

Thank you. 谢谢。

If you don't want the suggestion by @starkeen which is very vital you could do this : 如果您不想要@starkeen的建议,这非常重要,您可以这样做:

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

and let them treated as error requests. 并将它们视为错误请求。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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