我已经用Codeigniter和开发了一个应用程序
我想从此-重写我的GET查询字符串
https://www.example.com/search?state=American%20Samoa
到这个
https://www.example.com/job-vacancies-in-American-Samoa
我可以选择任何带有.htaccess或CI-route.php的解决方案
我当前的.htaccess包含
RewriteOptions inherit
RewriteEngine on
#Force https:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#CI index.php removal
RewriteCond $1 !^(index.php|public|.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1
RewriteRule ^admin/(.*)$ /$1 [L,NC,R]
在控制器中尝试这种方式
public function search(){
if(!empty($this->input->get('search'))){
$search = $this->input->get('search');
$joined_search='job-vacancies-in-'.$search;
redirect($joined_search);
}
}
在routes.php中,考虑默认控制器是否受欢迎
$routes['(:any)']="welcome/search/$1";