【问题标题】:Show the link as if it was linked to the file using htaccess显示链接,就好像它使用 htaccess 链接到文件一样
【发布时间】:2018-11-05 03:01:45
【问题描述】:

我们可以使用 htaccess 显示这样的 url

http://www.example.com/group/goroupName

我在pages 文件夹中有group.php 文件。我想显示上面的网址。

这个规则我试过了

RewriteRule ^group/([\w-]+)/?$ pages/group.php?group_username=$1 [L,QSA]

但某些包含的 php 文件未显示。例如:

<?php 
    include_once '../../functions/includes.php';
   if(isset($_GET['group_username'])) {
    $group_username=$_GET['group_username'];
    include_once '../../functions/includes/get_group.php';  
    if(empty($group_profile_owner_id)){
      header("Location:$url404");
    }
   }else{
      header("Location:$url404");
   }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta name="theme-color" content="#8e24aa">
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">
<title><?php echo $group_username;?></title>
<?php include("../../themes/$getTemplate/contents/style_js.php");?>
</head>

<body>

在上面的代码中,这包括不显示:

<?php include("../../themes/$getTemplate/contents/style_js.php");?>

我的RewriteRule有什么问题

【问题讨论】:

  • 您能否提供更多信息,关于未显示的文件是什么?如果我理解您的问题,您可以找到解决方案here
  • @CharfiOmar 谢谢你的回答。我刚刚添加了未显示文件的示例。
  • @anubhava 我确实尝试过,但当时几乎是同样的问题。
  • @anubhava 因为它是全局文件,所有cssjs 文件都在style_js.php 文件中我只是在这里用style.css 写一个例子
  • @anubhava 现在它正在工作,这意味着我的RewriteRule 是正确的,对吧?

标签: .htaccess


【解决方案1】:

您的RewriteRule 是正确的,应该可以工作。

问题在于您使用相对路径的PHP 中的include 函数。由于 URL 重写,此相对路径发生了变化。

您最好使用来自DOCUMENT_ROOT 的相对路径:

<?php
   include($_SERVER['DOCUMENT_ROOT'] . '/themes/themeName/contents/style_js.php');
?>

【讨论】:

    猜你喜欢
    • 2016-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-13
    • 1970-01-01
    • 2017-02-17
    • 1970-01-01
    相关资源
    最近更新 更多