[英]configuring routes.php in Codeigniter
我只是一個人開始一個新項目,而我陷入了Codeigniter的URI配置中。
我正在使用xampp,到目前為止,我的網站中包含一個包含以下路徑的文件夾:
c:/xampp/htdocs/new_admin/site/application
c:/xampp/htdocs/new_admin/site/system
就像Codeigniter手冊中所說的那樣,我將config.php添加到了我認為是的基本URL:
$config['base_url'] = 'http://localhost/new_admin/';
我將index_page留為空白:
$config['index_page'] = '';
我希望我的URI看起來像:
http://localhost/new_admin/[controller]/[method]
例如:
http://localhost/new_admin/admin/index
因此,在文件route.php中,我這樣做:
$route['default_controller'] = 'admin';
$route['(:any)'] = 'admin/index';
但這甚至沒有顯示方法索引的結果。 錯誤是404。
由於我無法在文檔中找到解決方案,因此我想缺少一些東西。
我要如何做才能使它正常工作?
更新:我寫在.htaccess文件中
#Deny from all
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
ErrorDocument 404 /index.php
因此,經過一天的嘗試,我發現在配置虛擬主機時我錯了
c:/xampp/apache/conf/extra/httpd-vhosts.conf
現在是這樣並且工作:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "C:/xampp/htdocs/new_admin/site"
ServerName local.new_admin
</VirtualHost>
<Directory "C:/xampp/htdocs/new_admin/site">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
# to allow access from my local network add this line so other PC on my network are allowed in but not anything from the internet
# If you want the world to be allowed in uncomment this line
allow from all
</Directory>
然后
c:/windows/system32/drivers/etc/hosts
我添加了以下幾行:
127.0.0.1 localhost
127.0.0.1 local.new_admin #this is my site
修復后,我在此目錄中添加了一個新的.htaccess文件:
c:/xampp/htdocs/new_admin/site/
其中包含:
php_value memory_limit 64M
php_flag magic_quotes_gpc 0
php_flag magic_quotes_runtime 0
RewriteEngine On
RewriteBase /
#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]
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
在Codeigniter的application文件夾和system文件夾旁邊,以添加mod_rewrite權限
現在要訪問我的項目的語言環境,我只需輸入:
http://local.new_admin/admin/index
希望這對像我這樣的新手有用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.