使用.htaccess覆盖Codeigniter路由

问题描述 投票:0回答:1

是否可以使用htaccess中的RewriteRule而不是在routes.php中使用路由来屏蔽Codeigniter中的URL(不是重定向)?

我的目标是实现以下目标:

用户可以看到的URL - > https://example.com/search/query/page

实际网址 - > https://example.com/search?q=query&p=page

到目前为止我尝试过的,没有运气:

在routes.php - > $ route [“search /(:any)/(:any)”] =“search?q = $ 1&p = $ 2”;

在.htaccess - > RewriteRule ^ search /(.*)/(.*)$ / search?q = $ 1&p = $ 2 [NC,L]

我实际上已经考虑过将整个应用程序从查询字符串迁移到URL段,但不幸的是,我必然会使用来自客户端的现有代码库,并且迁移实际上不是一种选择。

任何帮助将非常感激 :)

.htaccess codeigniter mod-rewrite url-routing codeigniter-htaccess
1个回答
0
投票

试试这条路线:

Options All -Indexes
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
© www.soinside.com 2019 - 2024. All rights reserved.