【发布时间】:2015-10-02 17:16:55
【问题描述】:
我看过其他关于同一问题的文章。但是没有一个答案能解决我的问题。
我没有使用 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。请回复。非常感谢您的帮助。
【问题讨论】:
-
试试我的代码可能有帮助...
-
仍然显示未找到错误在此服务器上找不到请求的 URL /var/www/mytestsite.com/public_html/TestCI/index.php。
标签: php .htaccess codeigniter mod-rewrite