【问题标题】:mod_rewrite slash and header.php didn't include with slash in urlmod_rewrite 斜杠和 header.php 没有在 url 中包含斜杠
【发布时间】:2012-10-29 05:14:38
【问题描述】:

我的 .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>";
    }
    ?>

【问题讨论】:

  • @Brendan Scarvell 谢谢你我知道如果我从根加载(代码)没有 incloud 它会工作,但我需要 incloud

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


【解决方案1】:

我认为问题是路径问题。当我转到带有斜杠的页面时,它包括以下内容:

styles/assets/css/bootstrap.css

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

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

尝试让它从根目录加载:

/styles/assets/css/bootstrap.css

【讨论】:

    【解决方案2】:

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

    发件人:

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

    收件人:

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

    或者您可以在&lt;head&gt; 标签下方添加:

    <base href="/">
    

    问题是您的样式和脚本有相对链接。当浏览器尝试请求类似/20121028050853Test.html 的内容时,URI Base 就是/。但是当浏览器请求/20121028050853/Test.html时,base变成/20121028050853/,浏览器将使用这个base并将所有相关的URL附加到这个base,因此styles/assets/css/bootstrap.css变成/20121028050853/styles/assets/css/bootstrap.css,你不会得到任何样式或脚本。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-07-30
      • 2011-06-28
      • 2015-02-06
      • 1970-01-01
      • 2011-05-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多