我在同一个问题上看过其他文章。但是没有一个答案能解决我的问题。
我没有使用xampp或wamp但是单独设置了php mysql apache。此外,我使用自己的本地域名,例如mytestsite.com。
我的.htaccess文件如下所示:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /TestCI/
# Canonicalize Codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(HomeController(/index)?|index(\.php|html?)?)/?$ / [R=301,L]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [R=301,L]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(www|TestCI) [NC]
RewriteRule ^(.*)$ http://www.mytestsite.com/$1 [R=301,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]
</IfModule>
<IfModule !mod_rewrite.c>
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
</IfModule>
我还在config.php中进行了以下更改
$config['base_url'] = 'http://mytestsite.com/TestCI/';
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO'; //AUTO
我还在apache2.conf中进行了以下更改
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
但是当我尝试访问
时http://mytestsite.com/TestCI/HomeController/
显示404错误,但在使用
时正常工作http://mytestsite.com/TestCI/index.php/HomeController/
我已经查看了几个已经解决的类似问题,但没有一个答案对我有用。是否还需要执行其他操作才能从网址中删除index.php
。请回复。非常感谢。
答案 0 :(得分:1)
替换.htaccess
文件
RewriteEngine On
RewriteBase /project/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
答案 1 :(得分:1)
只需将此代码放入.htaccess:
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
答案 2 :(得分:1)
可能是没有使用htaccess。
在文件中放入sytax错误。 (在文件中附加类似hdtbf的内容)
如果没有出现500错误,则需要转为allow override all
在您的主Apache配置
http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride
答案 3 :(得分:1)
谢谢你的帮助......问题解决了。
我在apache2.conf文件中进行了以下更改
<Directory /Absolute path to .htaccess folder
AllowOverride All
Require all granted
</Directory>
我还删除了实际pbm所在的.htaccess文件中的RewriteBase参数。
我当前的.htaccess文件看起来像
<IfModule mod_rewrite.c>
RewriteEngine On
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
我也在config.php中进行了更改,我将$ config [&#39; base_url&#39;]更改为codeigniter根路径