2013-05-26 53 views
6

我已經閱讀了一段時間,我無法使其工作。Mod_rewrite已啓用,但無法正常工作

mod_rewrite的是Apache的啓用,我已經改變了AllowOverride所有

我的.htaccess看起來是這樣的:

Options +FollowSymLinks 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ profile.php/?username=$1 [L] 

和我的Apache2默認文件看起來是這樣的: 的ServerAdmin網站管理員@本地

DocumentRoot /var/www 
    <Directory /> 
      Options FollowSymLinks 
      AllowOverride all 
    </Directory> 
    <Directory /var/www/> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride all 
      Order allow,deny 
      allow from all 
    </Directory> 

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/ 
    <Directory "/usr/lib/cgi-bin"> 
      AllowOverride None 
      Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch 
      Order allow,deny 
      Allow from all 
    </Directory> 

    ErrorLog ${APACHE_LOG_DIR}/error.log 

    # Possible values include: debug, info, notice, warn, error, crit, 
    # alert, emerg. 
    LogLevel warn 

    CustomLog ${APACHE_LOG_DIR}/access.log combined 

是error.log

[Sat May 25 20:13:21 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:13:21 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:13:22 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:13:23 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:14:56 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not$ 
[Sat May 25 20:14:57 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not$ 
[Sat May 25 20:14:59 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not$ 
[Sat May 25 20:14:59 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbf', perhaps misspelled or defined by a module not$ 
[Sat May 25 20:15:04 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:15:04 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:15:20 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:15:20 2013] [alert] [client (ip)] /var/www/.htaccess: Invalid command '\xef\xbb\xbfRewriteEngine', perhaps misspelled or defined by$ 
[Sat May 25 20:15:58 2013] [notice] caught SIGTERM, shutting down 

在我的網站,我得到一個500內部服務器錯誤消息。請幫忙!

+1

_」在我的網站上,我得到一個500內部服務器錯誤信息。「_ - 然後查看服務器的錯誤日誌! – CBroe

+0

剛剛添加了error.log,要添加access.log以及它是否顯示任何內容。 – TheMeisterSE

+0

正如anubhava已經說過的那樣,這看起來像你的文件有點混亂 - '\ xef \ xbb \ xbf',這似乎是一個字節順序標記。如果apache在你的文件的第二行抱怨這個,那麼它看起來像你用編輯器編輯了一個UTF-8編碼文件,該編輯器在添加第一行或其他內容時沒有正確處理這個文件。 _Type_(不復制和粘貼)這些行到一個新的文件再次,並保存爲純ASCII - 應該解決這個問題。 – CBroe

回答

2

試着改變你的代碼如下:

Options +FollowSymLinks -MultiViews 
# Turn mod_rewrite on 
RewriteEngine On 
RewriteBase/

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.+)$ profile.php/?username=$1 [L] 

即關閉MultiViews選項關閉。

PS:看着你的error.log看起來像在你的.htaccess中有一些特殊字符在RewriteEngine關鍵字之前。 「