【问题标题】:URL Rewrite from base (without prefix) .htaccess从基础 URL 重写(无前缀).htaccess
【发布时间】:2015-04-23 03:29:12
【问题描述】:

我正在为一个品牌开发一个短链接网站,我需要让链接看起来像这样:

http://demo-name.com/[shortvalue]

我了解如何执行以下操作:

http://demo-name.com/l/[shortvalue]

但是,如果使用基本的重写规则,我不确定如何在没有 l 前缀的情况下执行此操作。

我还需要能够去

http://demo-name.com/file.php

运行某些文件,所以这需要成为可能。

如果也可以的话,我希望能够拥有一个

http://demo-name.com/[shortvalue]?key=val&key2=val2
                                 ^^^^^^^^^^^^^^^^^^

我的 URL 末尾的查询字符串,所以如果 [QSA] 也是可能的,那就太好了!

【问题讨论】:

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


    【解决方案1】:

    您可以测试文件是目录 (-d) 还是 RewriteCond 中的文件 (-f)。

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/\.]+)$ index.php?shorturl=$1 [L,QSA]
    

    此规则会将任何不带斜线或点的“短值”重写为index.php?shorturl=shortvalue

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-01
      • 1970-01-01
      • 2022-11-24
      • 2011-04-28
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多