【问题标题】:How Best to Write HTAccess如何最好地编写 HTAccess
【发布时间】:2018-12-20 21:26:57
【问题描述】:

我有一个网址

http://example.com/buildings/edit/index.php?f_id=2

我该怎么做

  1. .htaccess把网址改成

    http://example.com/buildings/edit/
    

  1. .htaccess 文件应该放在哪里?在最顶层的根目录或子文件夹中?

【问题讨论】:

    标签: php .htaccess url url-rewriting


    【解决方案1】:
    1. .htaccess把网址改成

       http://example.com/buildings/edit/
      

    您不要为此使用.htaccess - 除非您正在更改现有的 URL 结构并且旧的 URL 已被编入索引或链接到/添加书签。您“更改”应用程序中的 URL 并使用 .htaccess 将 URL 从 /buildings/edit/ 重写回 /buildings/edit/index.php?f_id=2

    但是,请求的 URL 中似乎没有足够的信息来完成此重写,除非您对 ?f_id=2 查询字符串进行硬编码。例如:

    RewriteRule ^(buildings/edit/)$ /$1/index.php?f_id=2 [L]
    
    1. .htaccess 文件应该放在哪里?在最顶层的根目录或子文件夹中?

    这可能取决于。但通常在文档根目录中只有一个 .htaccess。上面的指令假设这将进入文档根目录。

    【讨论】:

      猜你喜欢
      • 2019-02-17
      • 1970-01-01
      • 2023-03-24
      • 1970-01-01
      • 1970-01-01
      • 2012-08-14
      • 1970-01-01
      • 2015-03-25
      相关资源
      最近更新 更多