htaccess重写URL复杂问题

时间:2015-01-14 11:33:33

标签: php apache .htaccess mod-rewrite url-rewriting

http://my-domain.com/ppc-landing-page.php?Campaign=Boynton-Beach&AdGroup=Security%20System&Keyword=The%20Best%20Home%20Security%20System%20Company

我希望将其重写为

http://my-domain.com/Boynton-Beach/Boynton-Beach.php?Campaign=Boynton-Beach&AdGroup=Security%20System&Keyword=The%20Best%20Home%20Security%20System%20Company

并在ppc-landing-page.php

中显示内容

我们的想法是获取Campaign查询参数的值并将浏览器中的url重写为

http://my-domain.com/{$_GET['Campaign']}/{$_GET['Campaign']}.php?Campaign=Boynton-Beach&AdGroup=Security%20System&Keyword=The%20Best%20Home%20Security%20System%20Company

完整的查询字符串应该在那里

然后它应该用ppc-landing-page.php中的$ _GET值替换查询字符串中的值并显示内容。

2 个答案:

答案 0 :(得分:1)

在您网站的文档根目录的.htaccess中尝试以下RewriteRule

RewriteEngine On

RewriteBase /
RewriteCond %{QUERY_STRING} campaign=([^&]+) [NC]
RewriteRule ppc-landing-page.php %1/%1.php [R=302,L]

答案 1 :(得分:0)

RewriteCond %{REQUEST_URI} !^/ppc-landing-page.php
RewriteCond %{QUERY_STRING} campaign=([^&]+) [NC]
RewriteRule ^(.*)$ ppc-landing-page.php [L,QSA]

RewriteCond %{REQUEST_URI} ^/ppc-landing-page.php
RewriteCond %{QUERY_STRING} campaign=([^&]+) [NC]
RewriteRule ppc-landing-page.php %1/%1.php [R=302,L]

现在我已经把这样的东西......首先它现在起作用了它不是???