核心PHP中的URL掩码

时间:2017-06-14 14:38:16

标签: php url

这些是我在项目中使用的URL。

    http://example.com/add_candidate.php?id=12
    http://example.com/admin/access_author.php
    http://example.com/associate/support/edit_profile.php?a_id=10

我想隐藏文件名(网址屏蔽)

我的网址应该是

http://example.com/
http://example.com/admin/
http://example.com/associate/support/

这怎么可能。我尝试了很多方法,但我无法得到我想要的确切结果。如果有人知道解决方案,请帮助我。提前谢谢。

2 个答案:

答案 0 :(得分:0)

您可以插入任何路由库。就个人而言,我发现Bramus Router(https://github.com/bramus/router)很容易集成到现有项目中。

首先,您像这样在项目的根目录创建一个.htaccess文件

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

这使Apache将所有请求传递到index.php文件,然后在其中定义如下路由:

// Static route: /hello
$router->get('/hello', function () {
    echo '<h1>bramus/router</h1><p>Visit <code>/hello/<em>name</em></code> to get your Hello World mojo on!</p>';
});

答案 1 :(得分:-1)

这实际上不是一个php问题。 :)

如果您使用的是Apache HTTP服务器,我可能需要查看.htaccessmod_rewrite。它们是Apache的功能,可将服务器URL映射到PHP脚本。例如

http://example.com/associate/support/http://example.com/associate/support/edit_profile.php?a_id=10

这是一个很好的教程,介绍如何完成

[https://code.tutsplus.com/tutorials/an-in-depth-guide-to-mod_rewrite-for-apache--net-6708][1]