简体   繁体   English

htaccess文件中的Apache重写规则

[英]Apache rewrite rules in htaccess file

I am working in a project where we use codeigniter. 我正在使用Codeigniter的项目中工作。

If user goto http://www.example.com/products.html link then my router look like is 如果用户转到http://www.example.com/products.html链接,则我的路由器看起来像是

$route['product'] = "product/all_product";

If they click any category say computer the (s)he will redirect to http://www.example.com/computer.html and my router is 如果他们单击任何类别,例如计算机,他将重定向到http://www.example.com/computer.html,而我的路由器是

$route['category/(:any)'] = "product/category_product/$1"; //$1 = computer or electronics

How to do that using .htaccess file? 如何使用.htaccess文件执行此操作?

@SKG - the url for your codeigniter site will be mysite.com/index.php. @SKG-您的codeigniter网站的网址为mysite.com/index.php。 You can (and most people do) remove the index.php, so the default url is simply mysite.com 您可以(大多数人都可以)删除index.php,因此默认网址就是mysite.com

from there, if you have a controller Category with an index($var) function, you can access it via: mysite.com/category/(var) 从那里开始,如果您具有带有index($ var)函数的控制器类别,则可以通过以下方式访问它:mysite.com/category/(var)

if you have an existing page at mysite.com/computer.html and you would like it to go to mysite.com/category/(:any) - perhaps because that link is already "out in the wild" in many places and so you want to redirect people to the new url, then you'll want to do the redirect where the computer.html file is and then remap, as shown here: 如果您在mysite.com/computer.html上已有一个页面,并且希望转到mysite.com/category/(:any)-可能是因为该链接在许多地方已经“荒野”,因此您想将人们重定向到新的URL,然后您要在computer.html文件所在的位置进行重定向,然后重新映射,如下所示:

https://httpd.apache.org/docs/current/rewrite/remapping.html https://httpd.apache.org/docs/current/rewrite/remapping.html

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

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