叫笨控制器的方法我知道,在CI觀點,如果我把如何從視圖
hostname/projectname/controllername/methodname
,它會調用CI控制器的方法。
但這不起作用。它說請求url不存在。然而,如果我把,
hostname/projectname/index.php/controllername/methodname
它的工作原理。 有什麼問題?
叫笨控制器的方法我知道,在CI觀點,如果我把如何從視圖
hostname/projectname/controllername/methodname
,它會調用CI控制器的方法。
但這不起作用。它說請求url不存在。然而,如果我把,
hostname/projectname/index.php/controllername/methodname
它的工作原理。 有什麼問題?
您需要配置您的.htaccess文件以刪除index.php。
如果你還沒有.htaccess文件,然後follow this guide。
在代碼點火器,你會希望.htaccess文件看起來像:你的測試過程中www.domain.tld
與您的域名,本地主機,例如:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase/
### Code Igniter Updates
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(welcome(/index)?|index(\.php)?)/?$/[L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|subdomain) [NC]
RewriteRule ^(.*)$ http://www.domain.tld/$1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
###
# 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]
# 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]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
更換。
仍然不能正常工作:(。是否因爲我錯過了安裝mod_rewrite? – user2293633
mod_rewrite是Apache服務器安裝的一部分,因此您可能需要檢查您的本地apache安裝是否啓用了mod_rewrite。 –
我檢查與phpinfo(),我檢查它是在加載模塊。這是否意味着它是啓用的?如果是這樣,爲什麼它仍然不工作:( – user2293633
在htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
添加此參考http://ellislab.com/codeigniter/user-guide/general/urls.html
更新的完整代碼
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
你需要'安裝在服務器上mod_rewrite',你需要編輯你的'。 htaccess' – Basic