douqulv6059 2011-06-26 20:13 采纳率: 0%
浏览 82
已采纳

Apache mod_rewrite:我做错了什么?

I've got a really simple rewrite in my .htaccess file, but it doesn't exactly work the way I want. This is my code:

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteRule ^admin/?$ admin.php [L]
    RewriteRule ^([0-9]*).*$ index.php?id=$1 [L]
</IfModule>

Basically what I want is that every page is like this: /0/title. The title is just to make the URL clearer for the user, but the number (id) should be passed to my PHP script. With this code the id is not passed to my index.php script. It is passed to that script if I just remove ".*" from the fourth row, but then URL's with text after the number don't get passed to my index.php file.

What am I doing wrong? How can I fix this?

Thanks!

  • 写回答

1条回答 默认 最新

  • douhui8454 2011-06-26 20:16
    关注

    You are trying to trap URL's like /0/title, but you don't have a slash / in your match pattern. Try this instead:

    # Should match /01234/anything
    # with the "/anything" optional
    RewriteRule ^([0-9]+)(/.*)?$ index.php?id=$1 [L]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类