【问题标题】:Get the PATH in htaccess using $_GET in PHP在 PHP 中使用 $_GET 获取 htaccess 中的 PATH
【发布时间】:2020-11-15 01:30:35
【问题描述】:

假设我的网站是 example.com/pageone。

如何使用 $_GET 和 PHP 重写我的 htaccess 以获取 pageone 名称?

例如,在我的代码中,我想做这样的事情:

if($_GET['page'] === 'pageone' && file_exists('./pages/' . $_GET['page'] . '.php')) {
   require_once './pages/' . $_GET['page'] . '.php';
} else {
   require_once './pages/home.php';
}

【问题讨论】:

    标签: php .htaccess get


    【解决方案1】:

    这应该适用于您的情况

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-l
    
    RewriteRule ^(.+)$ index.php?page=$1 [QSA,L]
    

    现在您应该可以使用 $_GET['page'] 获取请求的页面

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-07-06
      相关资源
      最近更新 更多