2011-07-27 342 views
0

我正在使用ExpressionEngine並希望從我的URL中刪除index.php。我有這個.htaccess文件保存在根文件夾中。它在localhost上完美工作,但是當我將它上傳到服務器時,它不起作用。地址欄中顯示正確的網址,但頁面仍保留在主頁上。有小費嗎?.htaccess不在現場工作,但在本地主機上工作?

<IfModule mod_rewrite.c> 
    # Enable Rewrite Engine 
    # ------------------------------ 
    RewriteEngine On 
    RewriteBase/
    # Redirect index.php Requests 
    # ------------------------------ 
    RewriteCond %{THE_REQUEST} ^[^/]*/index\.php [NC] 
    RewriteCond %{THE_REQUEST} ^GET 
    RewriteRule ^index\.php(.+) $1 [R=301,L] 
    # Standard ExpressionEngine Rewrite 
    # ------------------------------ 
    RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /index.php/$1 [L] 
</IfModule> 

回答

1

確保您AllowOverride Directive in Apache被配置爲允許.htaccess文件和你的服務器有mod_rewrite安裝和激活。

在Mac OS X上,您會找到此文件在/etc/apache2/httpd.conf。查找<Directory>指令和將其更改爲:

<Directory /> 
    Options FollowSymLinks 
    AllowOverride All 
    Order deny,allow 
</Directory> 

你需要重新啓動Apache以便它可以讀取新的配置:

sudo /usr/sbin/apachectl restart 

如果您更願意使用GUI重新啓動Apache,請轉至Apple>系統預置>共享並切換Web共享服務旁邊的複選框。

如果您使用的是Windows或任何Linux版本,則採用相同的方法,但Apache配置可能位於不同的位置,尤其是在使用WAMPMAMP時。


另外,作爲參考,對於Removing index.php from ExpressionEngine URLs的 「官方支持方法」 通過EllisLab如下:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    # Removes index.php 
    RewriteCond $1 !\.(gif|jpe?g|png)$ [NC] 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ /index.php/$1 [L] 
    # If 404s, "No Input File" or every URL returns the same thing 
    # make it /index.php?/$1 above (add the question mark) 
</IfModule> 
相關問題