微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

php – 更改页面URL并获取前两个字母

如何更改页面URL查询获取前两个字母.在.htaccess或PHP

http://127.0.0.1/site/flowers/index.PHP?query=Bird
http://127.0.0.1/site/flowers/index.PHP?query=eagle

像这样 :

http://127.0.0.1/site/flowers/search/bi/bird.html
http://127.0.0.1/site/flowers/search/ea/eagle.html

Htaccess代码:127.0.0.1/site/.htaccess

RewriteEngine on 
RewriteRule ([^/\.]+)/?.html$index.PHP?query=$1 [L]

解决方法:

这是一个可用于此重定向的Javascript代码

<html>
<head>
<title>Form Post Example</title>
<script>
function prettySubmit(form, evt) {
   evt.preventDefault();
   var val = form.query.value.toLowerCase();
   window.location =
          form.action + '/' + val.substr(0, 2) + '/' + val.replace(/ /g, '+') + '.html';
   return false;
}

</script>
</head>
<body>
<form method="get" action="flowers/search" onsubmit='return prettySubmit(this, event);'>
   <input type="text" name="query">
   <input type="submit" value="Search">
</form>
</body>
</html>

然后你可以在site / .htaccess中有这个规则:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ([^/.]+)\.html$index.PHP?query=$1 [L,QSA,NC]

这会将您的网址转换为:

http://127.0.0.1/site/flowers/search/bi/bird.html

搜索栏中使用单词鸟进行搜索时.

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐