.htaccess mod_rewrite : rewriting querystring to path

标签 .htaccess mod-rewrite

我如何使用重写来更改:

/?tag=foo

致:

/标签/foo

我尝试过:

RewriteCond %{QUERY_STRING} ^tag=(.+)$
RewriteRule ^(.*)$ http://www.example.com/tag/$1 [L]

但是没有成功。

最佳答案

尝试以下操作:

RewriteCond %{QUERY_STRING} ^tag=(.+)$
RewriteRule ^(.*)$ http://www.example.com/tag/%1 [L]

通常使用重写来达到相反的效果。您确定不想执行以下操作吗?

RewriteRule ^tag/(.+)$ index.php?tag=$1 [L]

关于.htaccess mod_rewrite : rewriting querystring to path,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1217981/

相关文章:

php - url 中的 htaccess rewriterule 2 参数

.htaccess - 使用 URL 重写时出现问题(相对路径不起作用)

wordpress - 301 重定向不起作用 (WordPress) - [ URL 中带有 ?m=1 的 Probler ]

apache - CakePHP、CGI 和 mod_rewrite

php - 使用自定义 htaccess mod 重写时有效路由上的 Codeigniter 404

ajax - CORS - 如何在 Apache 的 httpd.conf 中忽略 OPTIONS 预检请求的身份验证?

.htaccess - 使用 ? 阻止特定网址与 htaccess

regex - mod_rewrite 和正则表达式 OR 条件

.htaccess 从子文件夹重定向到域无法正常工作

php - htaccess - mod_rewrite 将虚拟目录或文件作为参数传递回 index.php?