在我的.htaccess
文件
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.+$ /index.php [L]
</IfModule>
我的网站显示index.php
内的文件为我所有的webfiles。我试图摆脱必须放入mysite/index.php/filename
而直接进入mysite/filename
我的网址是http://local-news.today/subscribe
当我使用这个地址local-news.today/index.php/subscribe
时,它显示了订阅功能上的内容。
我的网站托管在godaddy。我也在用codeigniter。
我在我的htaccess文件中做了以下操作:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
将以下代码放入。htaccess
RewriteEngine on
RewriteCond $1 !^(index'.php|resources|robots'.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
和在application/config/config.php中找到以下行
$config['index_page'] = "index.php"
并将其替换为以下代码
$config['index_page'] = ""
一个简单的搜索"codeigniter mod_rewrite htaccess"显示了这个要点:
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
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>
所以基本上你的重写规则有点错。你需要像
这样的东西RewriteRule ^(.*)$ index.php?/$1 [L]
这是什么意思?^(.*)$
maches一切((.*)
)从开始(^
)到结束($
),并使用$1
追加到index.php?/
在您的示例中,您忘记将它附加到url的末尾…
根据我的经验,在共享主机上,您经常需要使用.htaccess
文件。这个对我来说很管用:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index'.php|resources|robots'.txt|static) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/?$1 [L,QSA]
但是您会注意到这里的最后一行与其他答案不同,?
出现在 /
之后而不是之前(或者根本没有)。因此,尝试将其作为基础.htaccess
,然后根据需要修改最后一行。可能还需要删除RewriteBase '
行。
我总是用这个,它很有魅力:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#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
#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.
ErrorDocument 404 /index.php
</IfModule>