drbfxb977777 2013-01-22 20:39
浏览 46
已采纳

Codeigniter:重写以删除index.php不起作用

I've just uploaded my website from my local server (XAMPP). It was working locally, but for some reason the rewrite to add index.php to my SEF URL's is not working in my public server. This is what I've got right now:

# Avoid listing directory
Options -Indexes

<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on

# manage language segment 
RewriteRule ^(es|en)/(.*) $2?lang=$1 [L]

# code that allows to get rid of index.php from URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]

</IfModule>

These URL's work:

www.example.com

www.example.com/index.php/aboutme

while URL's like this generate a 500 error:

www.example.com/aboutme

Here's another combination of condition and rule I tried to solve the index.php removal:

RewriteCond $1 !^(index.php|css|img|scripts|ckeditor|robots.txt|sitemap.xml) 
RewriteRule ^(.*)$ index.php/$1 [L]

But it generates a 500 error for any URL without index.php, including the root URL www.example.com

Could you help me fix this?

  • 写回答

1条回答 默认 最新

  • duanchen7036 2013-01-22 20:46
    关注

    There seems to be a typo in your RewriteRule.

    Try this:

    RewriteCond $1 !^(index.php|css|img|scripts|ckeditor|robots.txt|sitemap.xml) 
    RewriteRule ^(.*)$ /index.php/$1 [L]
    

    It works for us with Code Igniter. The only difference is the slash infront of index.php when compared to your second examples.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?