如何使用htaccess将用户友好的url转换为另一个url


how to convert user friendly url to another url with htaccess

我有一个用户友好的(http://example.com/root1/root2?root3=abc25),我想将其转换为另一个url(http://example.com/index.php?request=root1/root2?root3=abc25&root4=abcd)这是我的代码,当运行此代码时,我会得到此url(http://example.com/index.php?request=root1/root2)我不知道我的错误在哪里,请指引我。

Options -Indexes
Options +FollowSymLinks
Options -MultiViews
DirectoryIndex index.php
<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?request=$1 [QSA,L]
</IfModule>

您的重写规则看起来像MVC前端控制器的标准规则。你使用框架是偶然的吗?在这种情况下,答案在于框架如何处理路由。

如果您不使用框架,那么您的index.php文件将不得不以某种方式决定如何处理对http://example.com/index.php?request=root1/root2?root3=abc25&root4=abcd的请求,以便使其行为与http://example.com/root1/root2?root3=abc25相同。