【问题标题】:Overriding Codeigniter routing with .htaccess使用 .htaccess 覆盖 Codeigniter 路由
【发布时间】:2019-07-30 00:21:26
【问题描述】:

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

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

用户可见的 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 段,但不幸的是,我必须使用来自客户端的现有代码库,并且迁移并不是一个真正的选择。

任何帮助将不胜感激:)

【问题讨论】:

    标签: codeigniter mod-rewrite url-routing .htaccess


    【解决方案1】:

    试试这条路线:

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

    【讨论】:

    • 我很确定我的问题无法在 routes.php 中解决,因为路由不接受查询字符串。我确定我写的 htaccess 规则很好,它只是不适用于 CodeIgniter
    • 我已经更新了答案试试这个 htaccess。我也在使用。我希望它会帮助你。
    • 这样做的目的是从 URL 中删除 index.php,我已经在使用它,但它与我的查询字符串问题没有任何关系。不管怎么说,还是要谢谢你! :)
    猜你喜欢
    • 2012-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-23
    • 2017-12-04
    • 2023-03-26
    • 2014-05-28
    • 2017-08-02
    相关资源
    最近更新 更多