【问题标题】:.htaccess routing problem with GET method.htaccess 使用 GET 方法的路由问题
【发布时间】:2019-02-08 00:36:15
【问题描述】:

我的页面上有一个搜索引擎,它以 get 方法开头。搜索部分运行良好,但路由不行。我认为,我的 .htaccess 文件中会有问题,如下所示:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L]

RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

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

RewriteCond %{HTTP_HOST} !^www\.(.*)
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

所以当我点击搜索按钮时,它会将我重定向到 www.mysite.com/search?keyword=something。如果我将它从 URL 替换为 www.mysite.com/search/something 引擎工作。所以我只需要从.htaccess 重定向它。 你需要知道的,是不是我在Codeigniter里写的,路由部分是:

$route['/search/(:any)'] = "home/search/$2";

有什么想法吗?感谢您的帮助。

【问题讨论】:

  • 为什么不将表单提交到 /search/something ?
  • 不清楚您的问题。清楚地说明您需要做什么
  • 我只需要将 URL 从 www.mysite.com/search?keyword=something 通过 .htaccess 重定向到 www.mysite.com/search/something

标签: php .htaccess codeigniter url routing


【解决方案1】:

使用 php 重定向修改您的 Routes.php 文件

$route['/search/(:any)'] = "home/search/$2";

$route['search']['get'] = function ()
{
    $url='home/search/'.$_GET['keyword'];
    header("Location: $url");
die();
}; 

【讨论】:

    猜你喜欢
    • 2018-11-19
    • 2016-11-05
    • 1970-01-01
    • 1970-01-01
    • 2015-01-02
    • 1970-01-01
    • 2019-12-12
    • 2019-12-14
    • 1970-01-01
    相关资源
    最近更新 更多