显示链接,就好像它是使用htaccess链接到文件一样 [英] Show the link as if it was linked to the file using htaccess

查看:74
本文介绍了显示链接,就好像它是使用htaccess链接到文件一样的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们可以使用htaccess显示这样的网址吗?

can we show the url like this using htaccess

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

我在 group.php 文件中code>页面 文件夹 。我想显示上面的网址。

I have group.php file in the pages folder. I want to show the url like above.

我已经尝试过此规则

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

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

but some included php files not displayed. For example :

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

在上面的代码中未显示:

in the above code this include not displayed:

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

我的 RewriteRule <是什么问题/ p>

What is the problem in my RewriteRule

推荐答案

您的 RewriteRule 是正确的,应该可以使用。

Your RewriteRule is correct and should work.

问题是 PHP 中的 include 函数路径。由于URL重写,此相对路径更改。

Problem is with include function in PHP where you're using a relative path. Due to URL rewrite this relative path changes.

最好使用 DOCUMENT_ROOT 中的相对路径为:

You are better off using a relative path from DOCUMENT_ROOT as:

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

这篇关于显示链接,就好像它是使用htaccess链接到文件一样的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆