简体   繁体   English

在codeigniter中重写URL

[英]Rewrite URL in codeigniter

How can I completely avoid using the Codeigniter method of handling URLs and use the conventional way? 如何完全避免使用Codeigniter方法处理URL并使用传统方式?

Instead of [root_url]/index.php/controller/view/data , how can I just get [root_url]/view.php?variable=value&variable=value etc ... . 而不是[root_url]/index.php/controller/view/data ,我怎样才能获得[root_url]/view.php?variable=value&variable=value etc ...

If it matters, I am running and testing the site locally and not on the net. 如果重要的话,我正在本地运行并测试网站,而不是在网上。

If you're not intending on using CI for its URL handling, I would probably recommend using a different framework. 如果您不打算使用CI进行URL处理,我可能会建议使用不同的框架。

I would recommend keeping your entire application within the CodeIgniter scope. 我建议将整个应用程序保留在CodeIgniter范围内。 [base_url]/view/?param=value works just fine, and you can access GET requests via $this->input->get('param'); [base_url]/view/?param=value工作正常,你可以通过$this->input->get('param');访问GET请求$this->input->get('param');

Another option is enabling enable_query_strings , which gives you some control over how controllers/functions are routed. 另一个选项是启用enable_query_strings ,它可以控制控制器/功能的路由方式。 Have a look at enable_query_strings in the documentation on URLS at http://codeigniter.com/user_guide/general/urls.html 请访问http://codeigniter.com/user_guide/general/urls.html上的URLS文档中的enable_query_strings

Alternatively, If you don't want view.php in your CI app, [base_url]/view.php?param=value&etc= should load, but it'll exist outside the CodeIgniter scope. 或者,如果您不希望CI应用程序中的view.php, [base_url]/view.php?param=value&etc=应该加载,但它将存在于CodeIgniter范围之外。

If it's not loading, make If you have an .htaccess file and are redirecting traffic, make sure you have !-f and !-d flags for the REQUEST_FILENAME enabled, so that view.php isn't being redirected: 如果没有加载,请创建如果您有.htaccess文件并重定向流量,请确保启用了REQUEST_FILENAME的!-f和!-d标志,以便不重定向view.php:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM