Php CodeIgniter.htaccess和base_url()问题
我最近开始研究CodeIgniter,但是我在.htaccess和base_url()函数方面遇到了一些问题。我希望这只是一个noob错误,并有一个快速修复 现在使用.htaccess时,index.php从url中消失了,这很神奇,但现在我在用模板链接样式表和js文件时遇到了问题 在我阅读/观看的所有教程中,它们都包含了.htaccess,然后仍然设置了它们的基本url(),然后使用“link_tag(href);”链接它们的.css,但现在我得到了一个双重的url。例如,当我尝试添加样式表时,它查找的路径是:Php CodeIgniter.htaccess和base_url()问题,php,.htaccess,codeigniter,base-url,Php,.htaccess,Codeigniter,Base Url,我最近开始研究CodeIgniter,但是我在.htaccess和base_url()函数方面遇到了一些问题。我希望这只是一个noob错误,并有一个快速修复 现在使用.htaccess时,index.php从url中消失了,这很神奇,但现在我在用模板链接样式表和js文件时遇到了问题 在我阅读/观看的所有教程中,它们都包含了.htaccess,然后仍然设置了它们的基本url(),然后使用“link_tag(href);”链接它们的.css,但现在我得到了一个双重的url。例如,当我尝试添加样式表时
http://www.mysite.com/site/www.mysite.com/site/css/stylesheet.css
所以我的第一个想法就是删除我的base_url(),这样.htaccess就可以做任何事情,但它不起作用。有了.htaccess,我可以拥有一个没有index.php的站点,但没有链接的样式表或JavaScript文件,或者我可以拥有一个有一些样式的站点,但可以处理index.php。必须有一种方法,使两者同时工作
另外,我做了一个修复,没有使用link_tag(),我只是回显了一个正常的link标记,它在开始时工作得很好,但它仍然:
http://www.mysite.com/
但是,如果登录不正确,并且我重定向以再次加载登录视图,则样式将消失,因为它现在使用的是以下位置的相对路径:
http://www.mysite.com/user/login
提前谢谢!任何帮助都将不胜感激。试试看
RewriteEngine on
RewriteCond $1 !^(css|js)
RewriteRule ^(.*)$ /index.php/$1 [L]
因此www.mysite.com/css/mycss.css
通常被检索,其中aswww.mysite.com/something
被传递给codeigniter
要使用
base\u url()
获取css文件,您需要执行base\u url(“css/mycss.css”)
,这将导致“http://www.mysite.com/css/mycss.css“
更好的.htaccess规则集应该是:
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
这不允许访问您的系统和应用程序文件夹,但允许访问所有其他文件,例如:/js/*,/css/*,/img/*等。 @ NICCORIN,如果这对您有用,请考虑支持和接受答案。谢谢。您只需将php文件完全放在其他地方,此目录中只需要index.php(以及css/js等静态目录)