mod_rewrite斜杠和header.php没有在url中包含斜杠

时间:2012-10-28 10:24:36

标签: php .htaccess mod-rewrite url-rewriting rewrite

我需要帮助我的 .htaccess 文件..现在我有http://www.afrogfx.com/20121028050853/Test.html这样的链接 问题位于斜线/ !!如果你点击我的链接,你会发现没有风格的链接如果删除斜线,你将得到404 Not Found Like That http://www.afrogfx.com/20121028050853Test.html 试试吧 !! 这是我的.htaccess

    RewriteEngine On

    RewriteRule ^([a-zA-Z0-9-/]+).html$ readmore.php?url=$1
    RewriteRule ^([a-zA-Z0-9-/]+).html/$ readmore.php?url=$1

readmore.php

    <?php
    include ('config/connect_to_mysql.php');
    $url=$_GET['url'];
    if($_GET['url'])
    {
    $url=mysql_real_escape_string($_GET['url']);
    $url=$url.'.html'; //Friendly URL 

    $sql=mysql_query("select * from posts where url='$url'");
    $count=mysql_num_rows($sql);
    $row=mysql_fetch_array($sql);
    $title=$row['title'];
    $text=$row['text'];
    }
    else
    {
    echo '404 Page.';
    }

    ?>

问题

    <?php
    include('styles/header.php');
    include ('styles/leftblock.php');
    include ('styles/mrnuleft.php');
    ?>






    <?php
    if($count)
    {

    echo "<h1>$title</h1><div class='text'>$text</div>";
    }
    else
    {
    echo "<h1>404 Page.</h1>";
    }
    ?>

2 个答案:

答案 0 :(得分:0)

我认为问题是路径问题。当我使用斜线进入页面时,包括:

styles/assets/css/bootstrap.css

所以它试图包含的内容实际上是:

http://www.afrogfx.com/20121028050853/styles/assets/css/bootstrap.css

尝试告诉它从根目录加载:

/styles/assets/css/bootstrap.css

答案 1 :(得分:0)

您可以将所有标题链接设为绝对:

自:

<link href="styles/assets/css/bootstrap.css" rel="stylesheet">

要:

<link href="/styles/assets/css/bootstrap.css" rel="stylesheet">

或者您可以在<head>标记下方添加:

<base href="/">

问题是您的样式和脚本有相对链接。当浏览器尝试请求类似/20121028050853Test.html的内容时, URI Base 只是/。但是当浏览器请求/20121028050853/Test.html时,基础变为/20121028050853/,浏览器将使用此基础并将所有相对网址附加到此基础,因此styles/assets/css/bootstrap.css变为/20121028050853/styles/assets/css/bootstrap.css,并且您没有样式或脚本。

相关问题