简体   繁体   English

RewriteRule htaccess和所有隐藏的php文件

[英]RewriteRule htaccess and hidden php file for all

I have a problem in RewriteRule htaccess: example: my php file is main.php we need to when user trying to www.mysite.com/hello , then show www.mysite.com/main.php for this expamle we have below code in .htacces: 我在RewriteRule htaccess中遇到问题:例如:我的php文件是main.php,当用户尝试访问www.mysite.com/hello时 ,我们需要这样做,然后显示www.mysite.com/main.php ,我们有以下代码在.htacces中:

# BEGIN Htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^hello/*$ main.php

but in this code if user can open www.mysite.com/hello and www.mysite.com/main.php 但是在此代码中,如果用户可以打开www.mysite.com/hellowww.mysite.com/main.php

I need if user trying www.mysite.com/main.php then show error 404 but if trying for www.mysite.com/hello view content of main.php 如果用户尝试访问www.mysite.com/main.php,则需要显示错误404,但是如果尝试访问www.mysite.com/hello,则需要查看main.php的内容

thank you;) 谢谢;)

You need to match against the actual request here: 您需要在此处与实际要求匹配:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /main\.php
RewriteRule ^ - [L,R=404]

You can add that just under RewriteEngine On if you want. 如果需要,可以在RewriteEngine On下添加它。 The other way of dealing with this is to maybe check for $_SERVER['REQUEST_URI'] in your main.php script and if it's /main.php , instead of serving content, return a 404 response. 解决此问题的另一种方法是检查main.php脚本中的$_SERVER['REQUEST_URI'] ,如果它是/main.php ,而不是提供内容,则返回404响应。

You can't 404 main.php neither can you 301 it to /hello as it'll go into infinite loop. 您无法404 main.php,也无法将其301到/ hello,因为它将进入无限循环。 You'll have to check the url in main.php and if it is different than hello, redirect it to /hello 您必须检查main.php中的url,如果与hello不同,则将其重定向到/ hello

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

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