donglian8407 2012-10-21 20:48
浏览 34
已采纳

使用多个参数时.htaccess重写错误

I have this in my .htaccess :

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule . /index.php

and this is how i work with the parameters :

<?php
    $request = $_SERVER['REQUEST_URI'];
    $request = substr($request,1);
    $params = explode('/', $request);
    $safe_pages = array('page1','page2','page3');
    if(in_array($params[0],$safe_pages))
            {
                include($params[0].'.php');
            }else
            {
                include('404.php');
            }
?>

Let's say my site is : www.site.com

www.site.com/page -> works perfectly

www.site.com/page/parameter -> doesn't load any css or images because it looks for them in root/page instead of root/

I tried to use absolute links for my css and images but it still didn't work, so i guess the problem is in the .htaccess or i'm missing something.

  • 写回答

2条回答 默认 最新

  • dp19001 2012-10-21 21:00
    关注

    The problem lies not within htaccess rewrite rules, but in your html - yuor links to static content (like css, images or scripts) should start with slash to be ralative to the domain. So instead of

    <link href="css/style.css" />
    <script src="js/script.js"><script>
    

    Use

    <link href="/css/style.css" />
    <script src="/js/script.js"><script>
    

    Other way is to use base tag but it can break named anchors on your page

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错