douji1058 2012-04-05 07:33
浏览 10
已采纳

Mod Rewrite Rule重写错误

In my .htaccess file i have the following re-write rule

RewriteRule ^([a-z]*)$ work.php?album=$1 [L]

I am reading all directories in root directoy and creating links like

code in PHP

$dir=glob('images/works/*');
$dir_listing=array();
foreach($dir as $list)  
{
if(is_dir($list))
$dir_listing[]= (basename($list));
}
foreach($dir_listing as $folders )  
echo"<a href='$folders' ><img src='Default-thumbnail-folder.jpg' /> </a>";

the problem is i have three folders under works directory {alb,ban,bas}

the first and last {alb and bas} work properly for my redirect rule URL{siteName/works/bas}

but the second {ban} creates a URL like {siteName/works/ban/} Notice the extra "/" is creating the problem, it seems for some folder names it is creating the problem, so please help me in creating a proper redirect rule

i want a link like

<a href="alb" >About</a> // to redirect to work.php?content=about

I also notice that if URL in browser is like work/alb/ CSS is not applied i tried

<link href="sample.css" rel="stylesheet" type="text/css" />

and

<link href="css/sample.css" rel="stylesheet" type="text/css" />

it does not work for URL like {works/about/} it works for {works/about}

  • 写回答

2条回答 默认 最新

  • dongmeng1402 2012-04-05 07:59
    关注

    Easy!

    Try to change your rewriterule to:

    RewriteRule ^([a-z]*)/?$ work.php?album=$1 [L]
    

    So that the "/" at the end may or may not be present, in both cases it's ok.

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

报告相同问题?

悬赏问题

  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助
  • ¥15 STM32控制MAX7219问题求解答