使用codeigniter自定义URL htacess自定义、codeigniter、htacess、URL

2023-09-02 00:46:22 作者:不爱几个人渣怎知货比三家

我正在开发一个网站上codeigniter 2.0.2。它的一个网站,企业/用户可以注册并创建自己的个人资料页,有自己的自定义URL(如的http:// Facebook的。 COM / demouser ),有自己的反馈系统,显示他们的服务。

这说,我已经成功地显示在以下格式的个人资料页面

http://mainwebsite.com/company/profile/samplecompany 这为公司 samplecompany ,其中公司是控制器和配置文件是方法显示的主页。

现在我有几个问题,

我想这是可以创建有/ GET http://mainwebsite.com/samplecompany使用htaccess以及一个默认的控制器。如果有人可以帮助htaccess的规则,这将是真棒。我已经使用htacess从CI删除的index.php,但不能得到这个工作。

将有一些其他的网页给定用户/企业如反馈,请联系我们,服务等,让前来我心中的实现链接的形式为 ` http://mainwebsite.com/company/profile/samplecompany/feedback 或 http://mainwebsite.com/samplecompany/feedback

finebi中自定义了url后登入不了怎么办

http://mainwebsite.com/company/profile/samplecompany/services 或 http://mainwebsite.com/samplecompany/services

http://mainwebsite.com/company/profile/samplecompany/contactus 或 http://mainwebsite.com/samplecompany/contactus

其中, samplecompany`是动态部分 是否有可能在格式创建网站的链接?

在我了解使用给定域的A记录,我可以点一个域说, http://www.samplecompany.com 来 http://mainwebsite.com/company/profile/samplecompany 所以打字< A HREF =htt​​p://www.samplecompany.com相对=nofollow> http://www.samplecompany.com 他应采取的 http://mainwebsite.com/company/profile/samplecompany 。如果这是成功实施,将 http://www.samplecompany.com/feedback http://www.samplecompany.com/services http://www.samplecompany.com/contactus

工作是否正确?

解决方案   

我想这是可以创建有/ GET http://mainwebsite.com/samplecompany 使用htaccess的和默认控制器。如果有人可以帮助htaccess的规则,这将是真棒。我已经使用htacess从CI删除的index.php,但不能得到这个工作。   会有一些其他的网页给定用户/企业如反馈,请联系我们,服务等,让前来我心中的实现链接的形式'的 http://mainwebsite.com/company/profile/samplecompany/feedback 或的 http://mainwebsite.com/samplecompany/feedback

您可以做到这一点使用路线的。例如,在你的 /config/routes.php 文件,把这个:

  $航线['samplecompany'] =公司/个人资料/ samplecompany;
$航线['samplecompany /(:任何)'] =公司/型材/ samplecompany / $ 1;
 

第一条规则告诉codeIgniter,当有人访问 http://mainwebsite.com/samplecompany 的它应该处理它,如果该URL是公司/个人资料/ samplecompany。第二条规则捕获任何东西来在URI字符串samplecompany后,并追加其到年底。

不过,如果你有多个公司(不只是samplecompany),你可能会想延长CI的路由器,除非你想手动编辑一个新的公司加入,每次配置文件来suppor这一点。

好了,你肯定会想处理充满活力的公司名称(根据您的评论)。这是一个有点棘手。我不能给你完整的code,但我可以在正确的方向指向你。

您会想扩展CI的路由器和对传入的请求查询数据库为公司名称的列表。如果URI段匹配的公司名称,你想用你的公司/个人资料的方法来服务它。如果没有,你会忽视它让CI处理它正常。看看这个帖子关于这个主题的更多信息:论坛链接

I am developing a site on Codeigniter 2.0.2 . Its a site where companies/users can signup and create their own profile page, have their own custom url(like http://facebook.com/demouser), have their own feedback system, display their services.

This said, I have been successful in display the profile page in the following format

http://mainwebsite.com/company/profile/samplecompany This displays the home page for the company samplecompany , where company is the controller and profile is the method.

Now I have few questions,

I guess it is possible to create to have/get http://mainwebsite.com/samplecompany using htaccess and a default controller. If anybody can help with the htaccess rule , that would be awesome. I am already using htacess to remove index.php from CI but could not get this working.

There will be few other pages for the given user/company such as feedback, contact us, services etc. So the implementation links that come to my mind is of the form ` http://mainwebsite.com/company/profile/samplecompany/feedback or http://mainwebsite.com/samplecompany/feedback

http://mainwebsite.com/company/profile/samplecompany/services or http://mainwebsite.com/samplecompany/services

http://mainwebsite.com/company/profile/samplecompany/contactus or http://mainwebsite.com/samplecompany/contactus

wheresamplecompany` is the dynamic part Is it possible to create site links in the format?

I understand using A record for a given domain, I can point a domain say, http://www.samplecompany.com to http://mainwebsite.com/company/profile/samplecompany so typing http://www.samplecompany.com he should be taken to http://mainwebsite.com/company/profile/samplecompany . If this is successfully implemented, will http://www.samplecompany.com/feedback http://www.samplecompany.com/services http://www.samplecompany.com/contactus

work correctly?

解决方案

I guess it is possible to create to have/get http://mainwebsite.com/samplecompany using htaccess and a default controller. If anybody can help with the htaccess rule , that would be awesome. I am already using htacess to remove index.php from CI but could not get this working. There will be few other pages for the given user/company such as feedback, contact us, services etc. So the implementation links that come to my mind is of the form ` http://mainwebsite.com/company/profile/samplecompany/feedback or http://mainwebsite.com/samplecompany/feedback

You can accomplish this using routes. For example, in your /config/routes.php file, put this:

$route['samplecompany'] = "company/profile/samplecompany";
$route['samplecompany/(:any)'] = "company/profiles/samplecompany/$1";

The first rule tells CodeIgniter that when someone accesses http://mainwebsite.com/samplecompany that it should process it as if the URL were "company/profile/samplecompany". The second rule captures anything that comes in the URI string after "samplecompany" and appends it onto the end.

However, if you have multiple companies(not just samplecompany), you're probably going to want to extend CI's router to suppor this unless you want to manually edit the config file each time a new company is added.

OK, you're definitely going to want to handle dynamic company names(as per your comment). This is a little trickier. I can't give you the full code, but I can point you in the right direction.

You'll want to extend CI's router and on an incoming request query the DB for the list of company names. If the URI segment matches a company name, you'll want to serve it up using your company/profile method. If it does not, you will ignore it and let CI handle it normally. Check out this post on this topic for more information: forum link.