donpvtzuux37724 2015-10-02 17:16
浏览 38
已采纳

使用自己的本地域时,使用.htaccess文件删除CodeIgniter中的index.php

I have seen other articles on the same issue. But none of the answers have solved my problem.

I am not using xampp or wamp but have setup php mysql apache seperately. Also I am using my own local domain for instance mytestsite.com.

My .htaccess file looks like this:

<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>

I have also made following changes in config.php

$config['base_url'] = 'http://mytestsite.com/TestCI/';    
$config['index_page'] = '';
$config['uri_protocol'] = 'PATH_INFO'; //AUTO

I have also made following changes in apache2.conf

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

But when i try to access

http://mytestsite.com/TestCI/HomeController/

its showing 404 error but works correctly when using

http://mytestsite.com/TestCI/index.php/HomeController/

I have looked into several similar questions that have been reported solved, but none of the answers have worked for me. Is there anything else that should be done to remove index.php from the url. Kindly respond back. Help highly appreciated.

  • 写回答

4条回答 默认 最新

  • douzhao2047 2015-10-03 06:54
    关注

    It may be the htaccess isn't being used.

    Put a sytax error in the file. (Append something like hdtbf to the file)

    If that doesn't give a 500 error you need to turn allow override all In your main Apache config

    http://httpd.apache.org/docs/2.2/mod/core.html#allowoverride

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条