如何重写htaccess 404
How to rewrite htaccess 404
我正在开发一个原始的 PHP Web 应用程序。但是,当我在 url 之后使用无效单词时遇到问题(仅用于检查)。
当前 htaccess 代码:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ .php [NC,L]
ErrorDocument 404 https://example.com/404
Options -Indexes
例如:
我需要 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 此页面)。我认为这需要重定向 404 页面。你有什么想法?
谢谢。
RewriteRule ^profile.php/.*$ /404pagehere.php [L]
如果您不想要 @starkeen
的建议,这非常重要,您可以这样做:
RewriteRule ^(.*)\.(php|html|htm)/.*$ - [L,R=404]
并将它们视为错误请求。
我正在开发一个原始的 PHP Web 应用程序。但是,当我在 url 之后使用无效单词时遇到问题(仅用于检查)。
当前 htaccess 代码:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)$ .php [NC,L]
ErrorDocument 404 https://example.com/404
Options -Indexes
例如:
我需要 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 此页面)。我认为这需要重定向 404 页面。你有什么想法?
谢谢。
RewriteRule ^profile.php/.*$ /404pagehere.php [L]
如果您不想要 @starkeen
的建议,这非常重要,您可以这样做:
RewriteRule ^(.*)\.(php|html|htm)/.*$ - [L,R=404]
并将它们视为错误请求。