在我的案例中,htaccess的代码是什么?

时间:2013-08-14 08:59:42

标签: apache .htaccess url mod-rewrite url-rewriting

之前较少描述的问题已被删除。

指定问题:

•问题已在声明中描述。请至少阅读一次..

•我的目标是拥有友好的网址。所以我做了一些动作..

  1. 它只适用于:^ thread / [(0-9)+] /(*?)$ thread.php?id = $ 1

  2. 但不使用此:^ thread / [(0-9)+] / page / [(0-9)+] /(*?)$ thread.php?id = $ 1& page = $ 2

  3. 我发现将'thread'(for 2)更改为另一个单词,如..

    1. ^ anotherWord / [(0-9)+] /页/ [(0-9)+] /(*?) $ thread.php?id = $ 1& page = 2
    2. (上)工作正常.. 但你们很多人都是这样做的。

      我的意思是,你有

      blog/id/1/blog-title.html    
      blog/id/1/page/2/blog-title.html    
      blog/edit/id/1    
      

      全部为您的blog.php

      blog.php?id=1    
      blog.php?id=1&page=2    
      blog.php?id=1&edit    
      

      这里,id,page和blog-title可以有任何价值。实际上id和page是$ _GET var。有了这个id,我可以从db。中取出博客标题。

      那么如何才能使工作友好的网址?请回复我..

1 个答案:

答案 0 :(得分:0)

将此添加到您的网络根.htaccess目录

中的/
RewriteEngine on
RewriteBase /

RewriteRule ^forum/(\d+)/response/[^/]*$ post.php?id=$1 [NC,QSA,L]

RewriteRule ^(thread|forum)/(\d+)(?:/page/(\d+))?/[^/]*$ $1.php?id=$2&page=$3 [NC,QSA,L]