【发布时间】:2016-02-14 18:34:56
【问题描述】:
我在使用 Wamp Server 从 Codeigniter 3 中的 url 中删除 index.php 时遇到问题。我是在文件 config.php (project_folder/application/config/config.php) 中更改
$config['base_url'] = '';
$config['index_page'] = '';
$config['uri_protocol'] = "REQUEST_URI";
并使用编写的代码创建与应用程序文件夹相同级别的 .htaccess 文件
<IfModule mod_rewrite.c>
# Turn on URL rewriting
RewriteEngine On
# If your website begins from a folder e.g localhost/my_project then
# you have to change it to: RewriteBase /my_project/
# If your site begins from the root e.g. example.local/ then
# let it as it is
RewriteBase /
# Protect application and system files from being viewed when the index.php is missing
RewriteCond $1 ^(application|system|private|logs)
# Rewrite to index.php/access_denied/URL
RewriteRule ^(.*)$ index.php/access_denied/$1 [PT,L]
# Allow these directories and files to be displayed directly:
RewriteCond $1 ^(index\.php|robots\.txt|opensearch\.xml|favicon\.ico|assets|forums)
# No rewriting
RewriteRule ^(.*)$ - [PT,L]
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]
</IfModule>
rewrite_module 开启,我的虚拟主机代码是
<VirtualHost *:80>
DocumentRoot "D:/work/project_Name/"
ServerName abc.local
<Directory "D:/work/project_Name/">
Order Allow,Deny
Allow from all
Require all granted
</Directory>
</VirtualHost>
使用这些更改和代码我的项目在没有 index.php 和错误抛出的情况下无法运行
abc.local/controllername
Not found
The requested URL /controllername/ was not found on this server.
谢谢!
【问题讨论】:
-
阅读本教程w3code.in/2015/09/…
-
上述问题已通过更改虚拟主机文件 httpd-vhosts.conf ( C:\wamp\bin\apache\apache2.4.9\conf\extra ) 解决。通过替换“Order Allow,拒绝”变成“所有人允许” 干杯!
标签: php .htaccess codeigniter url