.htaccess Codeigniter不';没有index.php就无法工作
我正在使用别名为works的MAMP。 Codeigniter位于.htaccess Codeigniter不';没有index.php就无法工作,.htaccess,codeigniter,codeigniter-2,httpd.conf,codeigniter-url,.htaccess,Codeigniter,Codeigniter 2,Httpd.conf,Codeigniter Url,我正在使用别名为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
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';
<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>
(我尝试了所有的uri_协议)
我在/User/me/works/project/web上创建并编辑了.htaccess文件/
我厌倦了所有关于这个问题的.htaccess文件
$config['base_url'] = 'localhost/works/project/web/'; //with http://
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
<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>
重新启动发动机
重写库/Users/me/works/project/web
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
#最后一个条件允许访问图像和css文件夹以及robots.txt文件
#Michael Radlmaier(mradlmaier)提交
1美元^(索引\.php | images | robots\.txt | css)
重写规则^(.*)$index.php/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php
创建错误,即:
[error][client::1]文件不存在:/Users/me/works/project/web/auth
当我使用RewriteBase时也是一样的/
mod_rewrite在phpInfo中处于活动状态
我找不到解决方案。您肯定没有安装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
到
取消对此行的注释:
#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>
LoadModule php5_module libexec/apache2/libphp5.so
DocumentRoot“/用户/用户名/位置/曾经/你/喜欢”
选项索引多视图+FollowSymLinks
允许超越所有
命令允许,拒绝
通融
在这里获取更多信息
重新启动MAMP
要了解mod_rewrite是否处于启用状态,请遵循Stackoverflow中的以下回答:
为了确保你的.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>
重新启动发动机
重写库/Users/me/works/project/web/
#如果URL的开头与其中一个不匹配。。。
1美元^(索引\.php | robots\.txt |资产|缓存|主题|上传| css |图像| js)
#通过index.php路由
重写规则^(.*)$index.php/$1[L]
上面授予了对某些文件夹的访问权限,rewritebase后面有一个斜杠
确保您有任何其他嵌套的.htaccess覆盖此嵌套的.htaccess。您肯定没有打开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
到
取消对此行的注释:
#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>
LoadModule php5_module libexec/apache2/libphp5.so
DocumentRoot“/用户/用户名/位置/曾经/你/喜欢”
选项索引多视图+FollowSymLinks
允许超越所有
命令允许,拒绝
通融
在这里获取更多信息
重新启动MAMP
要了解mod_rewrite是否处于启用状态,请遵循Stackoverflow中的以下回答:
为了确保你的.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>
重新启动发动机
重写库/Users/me/works/project/web/
#如果URL的开头与其中一个不匹配。。。
1美元^(索引\.php | robots\.txt |资产|缓存|主题|上传| css |图像| js)
#通过index.php路由
重写规则^(.*)$index.php/$1[L]
上面授予了对某些文件夹的访问权限,rewritebase后面有一个斜杠
确保您有任何其他嵌套的.htaccess覆盖了这个文件。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默认值
change the AllowOverride None to AllowOverride All.
最后重新启动服务器。在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默认值
change the AllowOverride None to AllowOverride All.
最后重新启动服务器我解决了这个问题,不再使用.htacces,而是将它们写入httpd.conf。 我检查了AllowOverride,但我不确定为什么。htaccess不工作。因为我在这个问题上浪费了太多的时间,我打算用这种方式。
谢谢你的回答。我解决了这个问题,不再使用.htacces,而是将它们写入httpd.conf。 我检查了AllowOverride,但我不确定为什么。htaccess不工作。因为我在这个问题上浪费了太多的时间,我打算用这种方式。
谢谢你的回答。你的
RewriteBase
错了。它不应该是服务器的相对文件路径,而应该是重写规则等的相对URL路径
如果您曾经使用过HTML的
标记,那么它的原理基本相同。如果主本地主机URL为http://localhost
,您的项目位于子文件夹http://localhost/my-project
,然后您将使用RewriteBase/my project/
如果未使用RewriteBase,并且项目位于子文件夹中,则必须将子文件夹添加到每个URL并进行重写,如下所示:
RewriteRule ^(.*)$ /my-project/index.php/$1 [L]
值得思考的是:
- 尽可能简单地启动.htaccess文件。你越是马上投入,就越可能出错,而且