apache - 重写查询 URL

标签 apache mod-rewrite

假设我有带有如下查询字符串参数的 URL:

index.php?lag=en&name=About Us&itemid=60
index.php?host=consumer&lag=en&name=About Us&itemid=64

使用 mod_rewrite,我怎样才能像这样重定向它们?

en_About Us_60.php
consumer/en_About Us_64.php

上面的 url 值是动态的。

最佳答案

类似这样的事情:

RewriteEngine on 
RewriteCond %{QUERY_STRING} host=(.*)&lag=(.*)&name=(.*)&itemid=(.*)
RewriteRule ^index.php(.*)$ /%1/%2_%3_%4 [QSA]

RewriteCond %{QUERY_STRING} lag=(.*)&name=(.*)&itemid=(.*)
RewriteRule ^index.php(.*)$ /%1_%2_%3 [QSA]

记住,检查所有可能的陈述;)

关于apache - 重写查询 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7755962/

相关文章:

java - 如何输出缓存文件并进行自定义日志记录 - jboss/java 项目

php - 在ubuntu容器上添加mysql数据库

javascript - URL 重写和获取参数未按预期工作

java - 在哪里可以找到 org.apache.common 库

apache - php 是否可以通过反向 ajax 长轮询进行扩展?

apache - 如何在使用 mod_proxy 的同时将用户发送到 Apache 中的另一个 "site"?

css - htaccess 在子域中重定向

apache - .htaccess HTTPS 并删除 index.php

apache - 虚拟主机和 htaccess 的重定向过多

Apache URL 重写并替换多个参数