【问题标题】:Rewriting query URL重写查询 URL
【发布时间】:2011-12-07 01:03:34
【问题描述】:

假设我有带有如下查询字符串参数的 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 显示在 en_About Us_60.php 中为用户并重定向到 index.php?lag=en&name=About Us&itemid=60 fot应用程序,不是吗?您确定要重定向还是只是透明重写?
  • 是的,我想重定向 index.php?lag=en&name=About Us&itemid=60 index.php?host=consumer&lag=en&name=About Us&itemid=64 这两个动态 url 到静态 url,比如 en_About Us_60.php 消费者/en_关于我们_64.php 这个。请帮帮我
  • 你说是,然后你说与我的句子相反...在你的问题中写下用户的 url 和你的应用程序的 url。您有 en_About Us_64.php 文件吗?

标签: apache mod-rewrite


【解决方案1】:

类似这样的:

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]

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-17
    • 2012-10-09
    • 2011-08-02
    • 2013-12-24
    • 2012-01-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多