【发布时间】:2018-12-20 21:26:57
【问题描述】:
我有一个网址
http://example.com/buildings/edit/index.php?f_id=2
我该怎么做
-
写
.htaccess把网址改成http://example.com/buildings/edit/
和
-
.htaccess文件应该放在哪里?在最顶层的根目录或子文件夹中?
【问题讨论】:
标签: php .htaccess url url-rewriting
我有一个网址
http://example.com/buildings/edit/index.php?f_id=2
我该怎么做
写.htaccess把网址改成
http://example.com/buildings/edit/
和
.htaccess 文件应该放在哪里?在最顶层的根目录或子文件夹中?【问题讨论】:
标签: php .htaccess url url-rewriting
写
.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]
.htaccess文件应该放在哪里?在最顶层的根目录或子文件夹中?
这可能取决于。但通常在文档根目录中只有一个 .htaccess。上面的指令假设这将进入文档根目录。
【讨论】: