简体   繁体   English

如何在PHP中隐藏URL

[英]How to hide the url in php

Is it possible to hide the the url in the address bar of the web browser so that it won't necessarily match the location of the files. 是否可以将URL隐藏在Web浏览器的地址栏中,以便它不一定与文件的位置匹配。 For example, this url: 例如,此URL:

http://localhost/exp/regstuds.php

You will always know by looking where to find the files in the computer. 通过查找计算机中文件的位置,您将始终知道。 Is it possible to distort or disarrange or hide the url in such a way that the location of the files will not be revealed 是否可能以不会泄露文件位置的方式扭曲或重新排列或隐藏网址

Yes, if you're using Apache look into using mod_rewrite . 是的,如果您使用的是Apache,请考虑使用mod_rewrite There are similar rewrite modules for pretty much all other web servers too. 对于几乎所有其他Web服务器也有类似的重写模块。

I hope your sole motivation for doing this is not "security through obscurity". 我希望您这样做的唯一动机不是“默默无闻的安全性”。 Because if it is, you should probably stop and spend more time on something more effective. 因为如果是这样,您可能应该停下来,花更多的时间在更有效的事情上。

If you are hosting your php on an Apache server, you probably have the ability to use the mod_rewrite utility. 如果您将PHP托管在Apache服务器上,则可能可以使用mod_rewrite实用程序。 You can do this be adding rules to your .htaccess file... 您可以通过向.htaccess文件中添加规则来做到这一点...

RewriteEngine on
RewriteRule ^RegStuds/ regstuds.php

This would cause http://localhost/RegStuds/ to actually render regstuds.php, but without ever displaying it in the address bar. 这将导致http:// localhost / RegStuds /实际呈现regstuds.php,但不会在地址栏中显示它。

If you are on IIS, you can perform the same function using an ISAPI Rewrite Filter. 如果您在IIS上,则可以使用ISAPI重写筛选器执行相同的功能。

If you don't have mod_rewrite or an ISAPI Rewrite Filter, you can get a similar result using a folder structure, so you would have a physical path of RegStuds/index.php - and you would never need to link to "index.php" as it is the default file. 如果您没有mod_rewrite或ISAPI重写过滤器,则可以使用文件夹结构获得类似的结果,因此您将拥有RegStuds / index.php的物理路径-无需链接到“ index.php ”,因为它是默认文件。 This is the least recommended way of doing it. 这是最不建议这样做的方法。

No its not. 不,这不对。

Each bit of functionality must have a unique identifier (URI) so that the request is routed to the right bit of code. 功能的每一位都必须具有唯一的标识符(URI),以便将请求路由到正确的代码位。 The mapping can be non-linear using all sorts of tricks - mod_rewrite, front controller, content negotiation...but this is just obscuring what's really going on. 使用各种技巧-mod_rewrite,前端控制器,内容协商...,映射可以是非线性的,但这只是掩盖了实际情况。

You can fudge what appears in the address bar on the browser by using a front-controller architecture and using forms / POSTs for every request but this is going to get very messy, very quickly. 您可以通过使用前控制器体系结构并为每个请求使用表单/ POST来捏造浏览器地址栏中显示的内容,但这会变得非常混乱,非常迅速。

Perhaps if you were to explain why you wanted to do this we might be able to come up with a better solution. 也许如果您要解释为什么要这样做,我们也许可以提出一个更好的解决方案。

C. C。

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

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