更改codeigniter中的网址

编程入门 行业动态 更新时间:2024-10-16 22:15:24
本文介绍了更改codeigniter中的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一个看起来像

的网址

mysite/index.php/home/user_get

这样工作正常。

URL中的哈希字符

mysite/username

有没有反正在代码igniter允许我使用这种类型的url我登录?

解决方案

要摆脱index.php前缀,你必须在你的apache配置文件中启用mod_rewrite,并使用htaccess重写url。

要启用mod_rewrite,请打开httpd.conf文件并取消注释以下行:

LoadModule rewrite_module modules / mod_rewrite.so

要重写URLS,必须将.htaccess文件(命名为.htaccess)放入您的网站根目录并添加以下内容

RewriteEngine On RewriteCond $ 1!^(index\.php | images | scripts | css | robots\.txt) RewriteRule ^(。*)$ /index.php/$1 [L]

b $ b

第三行很重要,因为它允许静态内容提供。您必须修改它以匹配您的项目结构。

我认为不可能使用户依赖。 请参见 mod_rewrite文档以供参考

UPDATE: 如果只是关于使用 mysite/username ,而不是 mysite/index.php/home/user_get 您可以使用单一方法

$ b定义 username $ b

public function index(){ redirect('/ home / user_get','refresh'); }

如果您要支持多个用户, mysite/john,mysite/dave,可能有帮助

RewriteEngine On RewriteCond $ 1 ^ \.php | images | scripts | css | robots\.txt) RewriteRule $ 1 [L] RewriteCond $ 1!^(products | categories) RewriteRule ^ 。*)$ /index.php/users/$1 [L] RewriteRule ^(。*)$ /index.php/$1 [L]

这将路由任何请求到未知的控制器到用户控制器。您必须在(products | categories)中列出所有控制器。在用户控制器中,您将有用户名作为参数,只要你的URL是/ users / username。请注意,这未经过测试。

I have a url that looks like

mysite/index.php/home/user_get

which works fine.

however my client now wishes to have a hashbang in the url

mysite/username

Is there anyway to in code igniter allow me to use this type of url whren i logged in?

解决方案

To get rid of index.php prefix you'll have to enable mod_rewrite in your apache config file and use htaccess to rewrite url.

To enable mod_rewrite, open httpd.conf file and uncomment the following line

LoadModule rewrite_module modules/mod_rewrite.so

To rewrite URLS you have to place .htaccess file (named exactly '.htaccess') into your site root and add the following lines to it:

RewriteEngine On RewriteCond $1 !^(index\.php|images|scripts|css|robots\.txt) RewriteRule ^(.*)$ /index.php/$1 [L]

Third line is important, as it allow static content to be served. You'll have to modify it to match your project structure.

Making user-dependent is impossible, I think. See mod_rewrite documentation for reference

UPDATE: If it is just about usning mysite/username instead of mysite/index.php/home/user_get you could define username controller, with single method

public function index(){ redirect('/home/user_get', 'refresh'); }

If you going to support several users, e.g. mysite/john, mysite/dave, that might help

RewriteEngine On RewriteCond $1 ^(index\.php|images|scripts|css|robots\.txt) RewriteRule $1 [L] RewriteCond $1 !^(products|categories) RewriteRule ^(.*)$ /index.php/users/$1 [L] RewriteRule ^(.*)$ /index.php/$1 [L]

this will route any requests to unknown 'controller' to users controller. You'll have to list all your controllers in (products|categories). In the users controller you will have username as parameter, just if your url would be /users/username. Please note that this is not tested.

更多推荐

更改codeigniter中的网址

本文发布于:2023-10-31 13:27:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546218.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:网址   codeigniter

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!