代码之家  ›  专栏  ›  技术社区  ›  Ian

关于动态url的mod_rewrite规则的帮助

  •  1
  • Ian  · 技术社区  · 17 年前

    http://example.com/a/name/

    http://example.com/a/index.php?id=name

    name index.php id

    4 回复  |  直到 17 年前
        1
  •  1
  •   outis    17 年前

    如果你想让尾部斜线是可选的,你必须排除你正在重写请求的文件。否则,你将得到一个很好的无限递归。

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !^/a/index\.php$
    RewriteRule ^/a/([^/]+)/?$ /a/index.php?id=$1 [L]
    

    在这里,任何以以下开头的请求 /a/… /a/index.php 被重写为 /a/index.php .

    RewriteEngine on
    RewriteRule ^/a/([^/]+)/$ /a/index.php?id=$1 [L]
    
        2
  •  2
  •   Gumbo    17 年前

    首先:

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !index.php
    RewriteRule ^/?a/([^/]+)/?$ /a/index.php?id=$1 [QSA,L]
    

    如果一个重写教程对你不起作用, try another .

    编辑:排除 index.php 根据Gumbo的建议

        3
  •  1
  •   laalto    17 年前

    也许是某种类似的东西

    RewriteEngine on
    RewriteBase /a/
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/?$ index.php?id=$1 [L,QSA]
    

    会成功的。

        4
  •  1
  •   Vinko Vrsalovic    17 年前
    推荐文章