简体   繁体   English

使用index.php来显示404页面

[英]using index.php to make 404 page show up instead

I am using a hosted wordpress site. 我正在使用托管的wordpress网站。

I don't like the idea of people accessing my wp-content folder, so I have added in the blank index.php in there. 我不喜欢人们访问我的wp-content文件夹的想法,因此我在其中添加了空白的index.php。

But I am not satisfied with this solution. 但是我对这种解决方案不满意。 To go a step further, is it possible for me to rewrite this index.php such that it does not just show a blank page, I want it to show a 404 page which I already have created. 更进一步,我是否可以重写此index.php,使其不仅显示空白页面,还希望它显示我已经创建的404页面。 What code should I put in there? 我应该在那输入什么代码?

you could put this in your index.php 您可以将其放在index.php中

<?php

header("HTTP/1.1 404 Not Found");

?>

Thanks all, in the end this is what I did, I added 谢谢,最后,这就是我所做的,我补充说

Options -Indexes
ErrorDocument 403 /

to my .htaccess file 到我的.htaccess文件

so when someone tries to access my plugin folder for eg. 因此,当有人尝试访问我的插件文件夹时,例如。 mysite.com/wp-content/plugins/abc-plugin , my 404 page appears. mysite.com/wp-content/plugins/abc-plugin,出现我的404页面。 However when I go to mysite.com/wp-content or mysite.com/wp-content/plugins, a blank page still shows up. 但是,当我访问mysite.com/wp-content或mysite.com/wp-content/plugins时,仍然会显示空白页。

But I guess its better than nothing, because when I first attempted using only 但我想它总比没有好,因为当我第一次尝试仅使用

 Options -Indexes

in my .htaccess, and I tried to access the plugin folder for eg. 在我的.htaccess中,我尝试访问例如的插件文件夹。 mysite.com/wp-content/plugins/abc-plugin , a 403 page with my hosting logo shows up, which I found it unsightly. mysite.com/wp-content/plugins/abc-plugin,显示一个带有我的托管徽标的403页,我发现它不太美观。

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

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