我正在使用名为works的别名的MAMP。
Codeigniter位于localhost/works/project/web
控制器在没有index.php之前无法工作(localhost/works/project/web/index.php/auth/register
)
$config['base_url'] = 'localhost/works/project/web/'; //with http://
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
$config['base_url'] = 'localhost/works/project/web/'; //with http://
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
(我为uri_protocol尝试了所有这些)
我在/ User / me / works / project / web /创建并编辑.htaccess文件 我厌倦了关于这个问题的所有.htaccess文件。
创建错误,即:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Users/me/works/project/web
#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
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</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>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /Users/me/works/project/web
#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
#This last condition enables access to the images and css folders, and the robots.txt file
#Submitted by Michael Radlmaier (mradlmaier)
RewriteCond $1 !^(index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</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>
当我使用RewriteBase /
时,它是相同的mod_rewrite在phpInfo中处于活动状态。
我无法找到解决方案。
答案 0 :(得分:3)
您的RewriteBase
错了。它不应该是服务器的相对文件路径,它应该是重写规则的相对URL路径等。 More info here.
如果你曾经使用过HTML的<base>
标签,那么它的原理基本相同。如果您的主要本地主机网址为http://localhost
,并且您的项目位于子文件夹http://localhost/my-project
中,那么您将使用RewriteBase /my-project/
。
如果您没有使用RewriteBase,并且您的项目位于子文件夹中,则必须将子文件夹添加到每个URL并重写,如下所示:
RewriteRule ^(.*)$ /my-project/index.php/$1 [L]
思考的食物:
尽可能简单启动.htaccess文件。你立即投入的越多,出错的次数就越多,调试就越困难。特别是如果你是.htaccess文件的菜鸟。不要盲目地复制和粘贴 - 弄清楚实际上做了什么。
系统文件夹访问部分现在是冗余的 - 系统文件夹有自己的.htaccess来限制请求,就像应用程序文件夹一样。
答案 1 :(得分:1)
1.在application / config.php文件中进行以下更改
$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.在.htaccess文件中使用它:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
并使用以下命令启用重写模式
a2enmod rewrite
并编辑文件/ etc / apache2 / sites-enabled / 000-default
change the AllowOverride None to AllowOverride All.
最后重新启动服务器
答案 2 :(得分:0)
您当然没有使用mod_rewrite或者没有使用MAMP安装它
打开httpd配置文件并更改
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
到
AllowOverride All
取消注释这一行:
#LoadModule rewrite_module libexec/apache2/mod_rewrite.so
此处还对用户进行了一些更改:/etc/apache2/users/username.conf
LoadModule php5_module libexec/apache2/libphp5.so
DocumentRoot "/Users/username/where/ever/you/like"
<Directory "/Users/username/where/ever/you/like">
Options Indexes MultiViews +FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
在此处获取更多信息http://adam.merrifield.ca/2010/08/09/apache-mod_rewrite-php-and-os-x-10-6-snow-leopard/
重启MAMP
要确定mod_rewrite是否已启用,请在Stackoverflow中按照以下答案进行操作:
How to check if mod_rewrite is enabled in php?
只是为了确保你的.htaccess不是问题,你能尝试一下吗?它已经过测试:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /Users/me/works/project/web/
# If the start of the URL doesn't match one of these...
RewriteCond $1 !^(index\.php|robots\.txt|assets|cache|themes|uploads|css|images|js)
# Route through index.php
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
上面授予对某些文件夹的访问权限,并且重写基础有一个尾部斜杠。
确保你有任何其他嵌套.htaccess覆盖这一个。
答案 3 :(得分:0)
我修复了问题,而不是使用.htacces,我将它们写入httpd.conf。 我检查了AllowOverride是All,但我不确定为什么.htaccess无效。因为我在这个问题上花了太多时间,所以我会用这种方式。 谢谢你的回答。
答案 4 :(得分:0)
在vhost上使用 AllowOverride All :
<Directory "/path/to/your/site">
....
AllowOverride All
</Directory>
答案 5 :(得分:0)
打开httpd配置文件 LoadModule rewrite_module modules / mod_rewrite.so然后 AllowOverride All
<Directory "C:/xampp/htdocs"> //example for xampp
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
答案 6 :(得分:0)
我在一个网址中安装了codeigniter,格式为:http://11.12.34.45/~project/
我尝试了不同的建议,最后这个url提供了解决方案:
https://ellislab.com/expressionengine/user-guide/urls/remove_index.php.html
答案 7 :(得分:0)
您需要更改Apache的两个文件, httpd.conf文件 的httpd-vhosts.conf
在httpd.conf中更改此内容
<Files ".ht*">
Require all denied
</Files>
要,
<Files ".ht*">
Require all granted
</Files>
并在httpd-vhosts.conf中添加以下代码,
<VirtualHost *:8000>
ServerName localhost
DocumentRoot c:/wamp64/www
<Directory "c:/wamp64/www/">
Options +Indexes +Includes +FollowSymLinks +MultiViews
AllowOverride All
Allow from all
</Directory>
</VirtualHost>