开发者

How to hide the url in php

开发者 https://www.devze.com 2022-12-31 09:08 出处:网络
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.

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. For example, this 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. There are similar rewrite modules for pretty much all other web servers too.

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. You can do this be adding rules to your .htaccess file...

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.

If you are on IIS, you can perform the same function using an ISAPI Rewrite Filter.

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. 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. 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.

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.

Perhaps if you were to explain why you wanted to do this we might be able to come up with a better solution.

C.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号