如何从重写url中删除变量并保留已删除的url变量

时间:2011-12-06 22:38:38

标签: php

我的索引页;

<form id="myfom" action="x.php" method="get">
<fieldset>

<select name="a1" id="a1">
<option value="o1">o1</option>
<option value="o2">o2</option>
</select>

<select name="a2" id="a2">
<option value="oo1">oo1</option>
<option value="oo2">oo2</option>
</select>

<select name="a3" id="a3">
<option value="ooo1">ooo1</option>
<option value="ooo2">ooo2</option>
</select>

<select name="a4" id="a4">
<option value="oooo1">oooo1</option>
<option value="oooo2">oooo2</option>
</select>

<select name="a5" id="a5">
<option value="ooooo1">ooooo1</option>
<option value="ooooo2">ooooo2</option>
</select>

<select name="a6" id="a6">
<option value="oooooo1">oooooo1</option>
<option value="oooooo2">oooooo2</option>
</select>


<script type="text/javascript">
function murl() {
    var grp1 = document.getElementById('a1').options[document.getElementById('a1').selectedIndex].value;
    var grp2 = document.getElementById('a2').options[document.getElementById('a2').selectedIndex].value;
    var grp3 = document.getElementById('a3').options[document.getElementById('a3').selectedIndex].value;
    var grp4 = document.getElementById('a4').options[document.getElementById('a4').selectedIndex].value;
    var grp5 = document.getElementById('a5').options[document.getElementById('a5').selectedIndex].value;
    var grp6 = document.getElementById('a6').options[document.getElementById('a6').selectedIndex].value ;
    var url = "http://www.domain.com/"+grp1+"-"+grp2+"-"+grp3+"-"+grp4+"-"+grp5+"-"+grp6+".html";

    document.forms["myform"].submit();
    window.location.href=url;
}
</script>
<input type="button" onclick="murl()" />
</fieldset>
</form>

htaccess文件是;

Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*)-(.*)-(.*)-(.*)-(.*)-(.*)\.html$ x.php?a1=$1&a2=$2&a3=$3&a4=$4&a5=$5&a6=$6 [L,QSA]

网站就像这样工作; http://www.domain.com/a1-a2-a3-a4-a5-a6.html

这是我的问题; 我想要像http://www.domain.com/a1-a2-a3.html

这样的网址

但我也希望在新页面上获取a4,a5,a6变量(在将表单提交到x.php之后)

尝试过RewriteCond%{QUERY_STRING}等许多内容,

任何帮助都会很棒..

此致

1 个答案:

答案 0 :(得分:0)

这是不可能的,至少不是直接的。如果您从URL中删除了内容,它就会消失。

您必须使用完整网址a1-a2-a3-a4-a5-a6.html调用PHP脚本,在session variable中存储a4-a6,然后header()重定向到a1-a2-a3.html。但是,如果同一个用户代理发出多个请求,这将导致问题 - 要解决此问题,您还可以检查目标页面上的$_SERVER["HTTP_REFERER"]

两者都相当复杂。你确定需要这个吗?

相关问题