2016-04-22 88 views
0

我有一个PHP的形式,并使用此页面上有以下功能:testsite.com/local-placesjQuery的AJAX提交表单,URL重定向或重写

jQuery(".submit").click(function() { 

      var dataString = jQuery("form#localsearch").serialize(); 

       $.ajax({ 
       type: "GET", 
       url: "/index.php", 
       data: dataString, 
        success : function(response) { 
        alert(response); 
        } 
       }); 
       return false; 

     }); 

提交表格后,网址是这样的:测试网站。 ?COM /局部地方/ post_type =本地& localtype =食品饮料& CATEGORY_NAME =西北奥斯汀

有没有一种方法,以消除/本地地方/直到结束:testsite.com/?post_type=local & localtype = food-drink & category_name = northwest-austin

在此先感谢!

+0

你返回false,所以URL不应该在所有当你改变提交表格? – adeneo

+0

返回false以免页面重新加载 –

回答

0

是的,有。

您需要使用.htaccess文件。这是一个纯文本文件,以点开头,结尾为htaccess - 不是第一部分。

尝试创建一个.htaccess文件只包含此(未测试):

RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME}.php -f 
RewriteCond %{REQUEST_URI} !/$ 
RewriteRule (.*) $1\.php [L] 

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+local-places/([^\s]+) [NC] 
RewriteRule^%1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule (?!^local-places/)^(.*)$ /local-places/$1 [L,NC] 

来源:

how to hide folder name from url using .htaccess