htaccess rewriterule不能在codeigniter中工作

时间:2015-02-24 10:38:04

标签: php .htaccess codeigniter rewrite

这里我试图在我的codeigniter应用程序中从URL中删除index.php。

为此,我写这样的.htaccess文件:

# Turn on URL rewriting
RewriteEngine On

# Installation directory
# RewriteBase /projectname/

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php [PT]

它在xx.xx.xx.xxx服务器和mydomain.com中运行。在这里,我试图将同一副本复制到另一台服务器yy.yy.yy.yyy。在此,重写URL无效。如果我使用&#39; yy.yy.yy.yyy / index.php / login&#39;,它的工作正常。但是&#39; yy.yy.yy.yyy / login&#39;,它会抛出我在此服务器上找不到请求的URL /项目名称/登录信息。&#39;错误。

1 个答案:

答案 0 :(得分:0)

对于您的主目录.htaccess尝试此操作,然后从config.php中删除index.php

Options +FollowSymLinks
Options -Indexes

<FilesMatch "(?i)((\.tpl|\.ini|\.log|(?<!robots)\.txt))">
    Order deny,allow
    Deny from all
</FilesMatch>

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA] 

请勿触摸应用程序目录中的.htaccess文件。