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]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

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