简体   繁体   English

htaccess:将file.php重定向到file.html,同时阻止对file.php的直接访问

[英]htaccess: Redirect file.php to file.html, and block direct access to the file.php at the same time

I would like to redirect a url help.html to help.php (internally) using .htaccess rewrite, but at the same time, I would like to give a 404 error message if someone tries to access help.php directly . 我想使用.htaccess重写将url help.html重定向到help.php(内部) ,但与此同时, 如果有人试图直接访问help.php ,我想提供404错误消息

I've seen alot of tutorials, and alot of questions answered, but none to this specific problem. 我已经看过很多教程,并且回答了很多问题,但没有解决这个具体问题。

Is this possible? 这可能吗?

Edit: For someone looking at the url from the outside, he would only see that help.html exists, but not help.php (even though internally only help.php exists, but not help.html) :) 编辑:对于从外面看url的人,他只会看到help.html存在,但不是help.php(即使内部只有help.php存在,但不是help.html):)

<Files help.php>
   order allow,deny
   Allow from 127.0.0.1
   deny from all
</Files>
RewriteEngine On
RewriteRule help.html$ help.php [L]

And you might wanna add AddType application/x-httpd-php .html to make the PHP execute now show as HTML/TEXT. 你可能想添加AddType application/x-httpd-php .html来使PHP执行现在显示为HTML / TEXT。

Edit: And you can give 404 error (cuz this htaccess will give 403 error) by adding this ErrorDocument 403 404.php and put 404 error HTML code in that page 编辑:你可以通过添加这个ErrorDocument 403 404.php给404错误(因为这个htaccess会给403错误)并在该页面中输入404错误HTML代码

在.htaccess文件中,您可以使用“permanent redirect”命令:

Redirect 301 /help.php /help.html

在x秒后,使用meta标记从help.php(404页面)重定向到help.html页面

<meta HTTP-EQUIV="REFRESH" content="10; url=http://www.yourdomain.com/help.html">

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

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