Url rewriting 仅重写url并保持在同一页面上

Url rewriting 仅重写url并保持在同一页面上,url-rewriting,Url Rewriting,我在stack上读了很多关于rewriterule及其应用的文章,我也试着在网上读了一些好文章,但我仍然不能对一些事情保持清醒的头脑 我有博客设置,所有文件夹都在其中 * 所以我把htaccess设置成这样 RewriteRule ^posts/post-tree/(.*)$ /index.php?$1 [R=301] 我相信您可以猜到,这基本上给我带来了root index.php,在这里我用$捕获了这个请求,以了解它请求的博客文件夹的名称 这很好,我可以点击index.php,使用$\u获

我在stack上读了很多关于rewriterule及其应用的文章,我也试着在网上读了一些好文章,但我仍然不能对一些事情保持清醒的头脑

我有博客设置,所有文件夹都在其中 *

所以我把htaccess设置成这样

RewriteRule ^posts/post-tree/(.*)$ /index.php?$1 [R=301]
我相信您可以猜到,这基本上给我带来了root index.php,在这里我用$捕获了这个请求,以了解它请求的博客文件夹的名称

这很好,我可以点击index.php,使用$\u获得他们请求的博客页面

我没有得到的,并且我已经尝试了很多方法,是一旦我在index.php中有了这个请求,我该如何重新编写URL以显示类似的内容而不是看起来类似的内容?哪里当然不是真的存在,但那是因为我想隐藏路径


这有点像wordpress处理带有id的博客页面,然后将url重写为为该博客页面设置的任何slug。至少我对它的理解是这样的,因为他们没有博客的单独文件夹,但我有。

我终于在htaccess文件中使用了以下内容

RewriteEngine on

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

#   the above checks if file or folder exists, if not the below is processed
#   this will route to base index file and fetch $1 folder via $_GET

RewriteRule . /posts/post-tree/index.php?$1