【发布时间】:2015-04-07 13:24:22
【问题描述】:
我在使用 codeigniter 和现有代码设置本地测试环境时遇到问题。
好吧,问题是,如果我的 URL 中没有“index.php”,我就无法打开页面。因此,“test.mydomain.local/index.php/search”可以正常工作,而“test.mydomain.local/search”则不行。但是代码中的所有链接,除了 form-tags 中的 action-URL,在 URL 中都没有这个“index.php”。
我该如何解决这个问题,codeigniter 或 xampp 在 URL 中需要这个“index.php”?我是否需要更改我的代码或 .htaccess 中的某些内容?
这是我的 config.php
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "index.php";
$config['uri_protocol'] = "AUTO";
好吧,这段代码在表单标签的action-URL中强制使用“index.php”。但实际上我不想在任何 URL 中有这个 index.php。所以我的 config.php 应该是这样的,我猜:
$config['base_url'] = "http://test.mydomain.local/";
$config['index_page'] = "";
$config['uri_protocol'] = "AUTO";
这是.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
### force www
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule (.*) h t t p : / / w w w . m y d o m a i n . c o m/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain.local [NC]
RewriteRule (.*) h t t p : / / t e s t . d o m a i n . l o c a l/$1 [R=301,L]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
### and the URI does not end with a /
RewriteCond %{REQUEST_URI} !^([^?]*)/($|\?)
### redirect and add the slash.
RewriteRule ^([^?]*) $1/ [L,R=301]
### if the is not a request for an existing file or directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# rewrite to index.php passing the URI as a path, QSA will preserve the existing query string
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
# 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
</IfModule>
有人可以帮助我吗?快把我逼疯了!
【问题讨论】:
-
有很多类似这样的问题和答案。您可以查看文档ellislab.com/codeigniter/user-guide/general/urls.html
标签: codeigniter url xampp uri