简体   繁体   English

CodeIgniter GET方法和SEO友好URL

[英]CodeIgniter GET method and SEO friendly URLs

In my web page search input I am using the get method, and the URL is something like this www.example.com/search?city=example&service=example2 , but I want a URL like this www.example.com/search/example/example2 ; 在我的网页搜索输入中,我使用的是get方法,URL像这样www.example.com/search?city=example&service=example2 ,但是我想要这样的URL www.example.com/search/example/example2 ; how can I convert? 我该如何转换?

Or maybe there is some other solution to get the data from html inputs and get a friendly URL? 或者,也许还有其他解决方案可以从html输入获取数据并获取友好的URL?

I think its help you and also SEO. 我认为它可以帮助您以及SEO。 Please write following uri rules in : application/config/routes.php 请在以下网址中编写以下uri规则: application/config/routes.php

$route['search-(:any)-(:any).html'] = 'search?city=$1&service=$2';

its rewrite your url from www.example.com/search?city=example&service=example2 to www.example.com/search-example-example2.html 它会将您的网址从www.example.com/search?city=example&service=example2重写为www.example.com/search-example-example2.html

In your routes.php file inside the config folder: 在config文件夹内的route.php文件中:

 $route['search/(:any)'] = 'search/searchFunction'; //You will now need to have a searchFunction() inside the controller search. Or you can just have 'search' and handle the code below inside the index() function. 

Now, inside your searchFunction: 现在,在您的searchFunction内部:

 function searchFunction() { $city = (isset($this->uri->segment(2))) ? $this->uri->segment(2) : null; //if you have www.example.com/search/example $service = (isset($this->uri->segment(3))) ? $this->uri->segment(3) : null; //if you have www.example.com/search/example/example2 //General Pattern is: www.example.com/uri-segment-1/uri-segment-2/uri-segment-3.....and so on. // Now when you are querying, if($city) then 'WHERE city = $city' and so on. //Also, in the link that was earlier triggering 'www.example.com/search?city=example&service=example2' //like <a href='www.example.com/search?city=example&service=example2'>Link</a> //Now have it as: // <a href='www.example.com/search/example/example2'>Link</a> } 

I see others posting about routing, yes i can do like what, but i think first i need to solve problem with html submit action, because when i press the button its auto redirect to what standart format url search?city=example&service=example2 , but like i say i need other format. 我看到其他人发布了有关路由的信息,是的,我可以喜欢,但是我认为我首先需要解决html提交操作的问题,因为当我按下按钮时,它会自动重定向到标准格式的url search?city=example&service=example2 ,但就像我说我需要其他格式。 So how i can solve this problem? 那么我该如何解决这个问题呢?

My form action 我的形式动作

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM