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条)

报告相同问题?

悬赏问题

  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题