繁体   English   中英

如何重写htaccess 404

[英]How to rewrite htaccess 404

我正在开发一个原始的PHP Web应用程序。 但是,当我在url之后使用无效的单词(仅用于检查)时,我遇到了问题。

目前的htaccess代码:

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

例如:

我需要https://example.com/profile (没有扩展名)。 现在正在使用以下htaccess代码。 当我打https://example.com/profile/lllflfllllflfl是无效的话,只是为了检查404错误),这是进入404错误页面。 哪个也好。 但是,当我点击https://example.com/profile.php/lllflfl时,我的网站仍显示当前页面(当前页面表示https://example.com/profile此页面)。 我认为这需要重定向404页面。 你有什么想法?

谢谢。

如果您不想要@starkeen的建议,这非常重要,您可以这样做:

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

并将它们视为错误请求。

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

暂无
暂无

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

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