doupijin0397 2018-08-12 21:53
浏览 63
已采纳

htaccess重写 - 文件名无法识别

Been working on this for days, but I can't seem to figure it out.

I have two files in a dir:

  1. index.php - which loads a list of articles in a news section
  2. article.php - which loads the article file itself with contents

Below, I get stuck on the first rule on the index.php file in the .htaccess file. (Tried many things, the includes and files are all OK, but the htaccess rules I have here don't get passed the index.php. The article file loads fine as well. Except when applying these two lines below.)

the link:

domain.com/news/index/66/bass (works)

Defined by:

RewriteRule ^/?news/[\w-]+/([\w-]+)/([\w-]+)/?$ /news/index.php?news_id=$1&page_id=$1 [QSA,NC]

Next, on that page we click to:

domain.com/news/article/66-17506/SEO-FRIENDLY-TITLE

Defined by:

RewriteRule ^/?news/[\w-]+/([\w-]+)/([\w-]+)/?$ /news/article.php?news_id=$1&page_id=$1 [QSA,NC]

And there I get stuck on the previous definition of index.php. I already deleted the [L] value and tried many things. I guess all that's needed is the article.php to be loaded.

Any help would save a lot of articles online!

  • 写回答

1条回答 默认 最新

  • duanbarong4617 2018-08-12 22:53
    关注

    The problem is that both your regexes for matching the URL are the same. So anything that might match the article.php rule will already have been grabbed by the index.php rule. Can you perhaps change the two rules to this:

    RewriteRule ^/?news/index/([\w-]+)/([\w-]+)/?$ /news/index.php?news_id=$1&page_id=$1 [QSA,NC]
    RewriteRule ^/?news/article/([\w-]+)/([\w-]+)/?$ /news/article.php?news_id=$1&page_id=$1 [QSA,NC]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码