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

报告相同问题?

悬赏问题

  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历