2013-05-26 28 views
6

Tôi đã đọc một lúc và tôi không thể làm việc này.Mod_rewrite được bật nhưng không hoạt động

mod_rewrite được kích hoạt trong Apache và tôi đã thay đổi AllowOverride cho tất cả

.htaccess của tôi trông như thế này:

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

và tập tin mặc định của tôi cho apache2 trông như thế này: ServerAdmin webmaster @ localhost

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 

Trên trang web của tôi, tôi nhận được thông báo lỗi máy chủ nội bộ 500. Hãy giúp tôi!

+1

_ “Trên trang web của tôi, tôi nhận được thông báo lỗi máy chủ nội bộ 500.” _ - sau đó xem nhật ký lỗi của máy chủ! – CBroe

+0

Chỉ cần thêm error.log, sẽ thêm access.log nếu nó hiển thị bất cứ điều gì. – TheMeisterSE

+0

Như anubhava đã nói, có vẻ như tập tin của bạn là một chút sai lầm - '\ xef \ xbb \ xbf', mà dường như là một dấu hiệu đơn hàng Byte. Nếu apache phàn nàn về điều này trên dòng thứ hai của tệp của bạn, thì có vẻ như bạn đã chỉnh sửa tệp được mã hóa UTF-8 bằng trình chỉnh sửa không xử lý đúng cách này trong khi thêm dòng đầu tiên hoặc thứ gì đó. _Type_ (không sao chép và dán) các dòng đó vào một tệp mới một lần nữa và lưu nó thành ASCII thuần túy - điều đó sẽ giải quyết được vấn đề này. – CBroe

Trả lời

2

Hãy thử thay đổi mã của bạn như thế này:

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

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

ví dụ: biến MultiViews tùy chọn tắt.

PS: Nhìn vào error.log của bạn trông giống như bạn có một số ký tự đặc biệt trong .htaccess trước RewriteEngine từ khóa.

Các vấn đề liên quan