【问题标题】:URL Masking filenames from URLs using core PHPURL 使用核心 PHP 从 URL 中屏蔽文件名
【发布时间】:2017-11-16 18:53:02
【问题描述】:

我想隐藏文件名(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/

这怎么可能?

【问题讨论】:

  • htaccess 就是你要找的东西
  • 你应该更好地使用像codeigniter这样的框架来做到这一点
  • 我不知道 codeigniter 我只在核心 PHP 中完成了我的整个项目。我应该知道核心 PHP 的任何可能性吗
  • 或者,如果您正在寻找一种更高级的 URL 处理方法,请尝试使用路由器,Slim 3 是一个您可以检查的简单框架。
  • URL rewriting with PHP的可能重复

标签: php url


【解决方案1】:

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

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

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

【讨论】:

    【解决方案2】:

    您可以插入任何路由库。就个人而言,我发现 Bramus 路由器 (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>';
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-31
      • 2018-10-21
      • 1970-01-01
      相关资源
      最近更新 更多