【问题标题】:Rewrite URL with query string .htaccess or route.php使用查询字符串 .htaccess 或 route.php 重写 URL
【发布时间】:2020-06-04 08:55:07
【问题描述】:

我已经用 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]

【问题讨论】:

    标签: php .htaccess codeigniter url-rewriting routing


    【解决方案1】:

    在你的控制器中尝试这种方式

    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";
    

    【讨论】:

      猜你喜欢
      • 2012-11-15
      • 1970-01-01
      • 2016-02-13
      • 1970-01-01
      • 1970-01-01
      • 2023-03-04
      • 2012-06-16
      • 2012-09-19
      • 1970-01-01
      相关资源
      最近更新 更多