输入文本sumit到无问号

时间:2014-04-10 03:14:59

标签: php html forms .htaccess

example.com/search/?q=english+videos <- i want to like this after enter -> example.com/search/english+videos

我也使用.htaccess文件..但现在想从表单操作中给出这样的url。现在我用这样的表格

example.com/search/index.php

<form name="menu_search" action="http://www.example.com/search/" method="get">

<input name="q" value="<?php if (!empty($_GET['q'])) { echo $_GET['q']; } ?>" id="videoSearch" />

</form>

这只是我的表单操作代码。有人在搜索example.com/search/?q=search+something这样的东西。我想example.com/search/search+something

帮助我。感谢...

/search/.htaccess

<Files .htaccess>
order allow,deny
</Files>

Options +FollowSymLinks
RewriteEngine On
RewriteBase /search/

RewriteRule ^([^/]+)(?:/[^/]+)?/?$ load.php?q=$1 [L,QSA]

RewriteRule ^([^/]+)/[^/]+/([0-9]+)/?$ load.php?q=$1&p=$2 [L,QSA]

RewriteRule ^search/(.*)$ load.php?q=$1 [L]

无法使用最后一条规则如何修复它... RewriteRule ^search/(.*)$ load.php?q=$1 [L]

1 个答案:

答案 0 :(得分:1)

你可以运行的快速而脏的javascript正则表达式是:

<script>
function removeQuestionMark()
{
var initialString = "example.com/search/?q=english+videos"; 
initialString  = initialString.replace(/\?/g, '');
console.log(initialString) //This just outputs to new string.
}
</script>

输出:example.com/search/q=english+videos

..虽然正则表达式将取代所有&#39;?&#39;。需要更复杂的正则表达式以确保您没有意外删除您可能想要的正则表达式。它可能适用于您想要做的事情。