我有一个看起来像
的网址 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_getwhich works fine.
however my client now wishes to have a hashbang in the url
mysite/usernameIs 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.soTo 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中的网址
发布评论