SEO / PHP的:如何转换表单提交URL(Get-Method)没有Javascript搜索引擎友好? [英] SEO/PHP: How to Convert Form-Submit URL (Get-Method) without Javascript SEO-Friendly?

查看:153
本文介绍了SEO / PHP的:如何转换表单提交URL(Get-Method)没有Javascript搜索引擎友好?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



实际上我用javascript转换了url

 < script type =text / JavaScript的> 
$(document).ready(function(){
$('。search-form')。submit(function(){

var value = $('。搜索表单输入:text')。val();
value = value = value.replace(/ \W /,''); //替换
window.location.href = value + -keyword+.html;
返回false;
});
});

< / script>

有没有方法可以将网址转换为不使用javascript的网址?也许与PHP?

解决方案

我为以下技术,因为


  1. 这是一个可以通过地址栏搜索的可猜测的URI

  2. 在响应POST请求时重定向总是一件好事,以避免尴尬想要再次发送POST信息? - 当用户试图通过浏览器的后退按钮返回时发出警报

  3. 如果URI清除了隐藏值,则可以更容易地查看搜索结果,提交按钮的价值等。

这里有:

<$ p $如果(isset($ _GET ['name_of_submit'],$ _GET ['search_phrase'])){
'<?php
//接收页面
标题(位置:/address_to_this_script/\".$_GET['search_phrase']);
死亡;

if(isset($ _ GET ['search_phrase'])){
//在这里处理搜索和验证,不要忘记逃脱它!
}


and actually i convert the url with javascript

<script type="text/javascript">
$(document).ready(function() {
    $('.search-form').submit(function() {

        var value = $('.search-form input:text').val();
        value = value = value.replace(/\W/,''); // replace
        window.location.href = value + "-keyword" + ".html";
     return false;
    });
});

</script>

is there a method to convert the url seo-friendly without javascript? maybe with php?

解决方案

I am for the following technique because

  1. it's a guessable URI to search "via the address bar"
  2. it's always a good thing to redirect while responding to a POST-request, to avoid awkward "want to send POST information again?"-alerts when the user tries to go back via the browser's back button
  3. it's simply easier to see what I searched for if the URI is clean of hidden values, value of submit-button etc.

Here goes:

<?php
//receiving page
if(isset($_GET['name_of_submit'], $_GET['search_phrase'])) {
    header("Location: /address_to_this_script/".$_GET['search_phrase']);
    die;
}
if(isset($_GET['search_phrase'])) {
   // handle search and validation here, don't forget to escape it!
}

这篇关于SEO / PHP的:如何转换表单提交URL(Get-Method)没有Javascript搜索引擎友好?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆