ds355020 2013-08-14 10:19
浏览 81
已采纳

为什么.htaccess url重写不工作codeigniter mamp?

[edit]: duplicate of How to remove "index.php" in codeigniter's path
[the solutions there dont work for me]

Im trying out codeigniter for the first time and im pretty new to php still. I wanted to remove the index.php from my url.

installed code igniter
replaced index.php that was there with my own

I have this in my .htaccess

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]  


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

#When your application folder isn't in the system folder
#This snippet prevents user access to the application folder
#Submitted by: Fabdrol
#Rename 'application' to your applications folder name.
RewriteCond %{REQUEST_URI} ^application.*
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
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>

My rewrite is definately on, i load a phpinfo page in my root and it shows the module loaded. Ive also checked the httpd.conf

when i run from NetBeans i am directed to localhost:8888/domain/index.php and my index page loads
when i go to localhost:8888/domain then my index.php also loads

when i go to localhost:8888/domain/welcome or localhost:8888/domain/welcome.php i get 404
The requested URL /index.php/welcome was not found on this server.
when i go to localhost:8888/domain/index.php/welcome i get directed to the welcome controller but it just loads my index.php but with no markup.

Ive also tried this in the .htaccess:

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [QSA,L] 

and i get:

enter code here

This also didnt work (i know, theyre all meant to be doing pretty much the same thing):

<IfModule mod_rewrite.c>

    RewriteEngine on
    RewriteBase /
    # Hide the application and system directories by redirecting the request to index.php
    RewriteRule ^(application|system|\.svn) index.php/$1 [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [QSA,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>

I have in config/config.php:

 $config['base_url']    = 'localhost:8888/domain.com/';
    $config['index_page'] = '';
  • 写回答

4条回答 默认 最新

  • duansan9435 2013-08-17 04:13
    关注

    I replaced my own index with the default CI index (that is, i returned it to how it was out of the box).
    I then routed domain/index.php/pages/view/page.php to domain/index.php/page.php
    i then ran Nishant's .htaccess code and although it didn't appear to work (a static non-style version of the site displayed at the usual url but not at the url without the index.php) it may have helped get me to a solution.
    i also changed RewriteEngine On to RewriteEngine on though im pretty sure i had tried that before. After these steps i then flicked back over to the code that sbaaaang suggested (which was somewhat a version id already unsuccessfully tried previously) and this time it worked.

    For anyone else who might run into .htaccess trouble i would suggest leaving things as they come out of the box and going through the tutes (instead of jumping into it like i did).

    My .htaccess ended up like this

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]  
    
    
    <Files "index.php">
    AcceptPathInfo On
    </Files>  
    </IfModule>
    
    <IfModule !mod_rewrite.c>
    
    ErrorDocument 404 /index.php
    </IfModule>
    

    and config vars like:

    $config['base_url'] = '';
    $config['index_page'] = '';
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题