localhost.htaccess가 우분투에서 작동하지 않습니다

localhost.htaccess가 우분투에서 작동하지 않습니다

.htaccess나는 내 파일을 내 로컬 호스트에서 작동시키려고 노력해 왔습니다 . 내 서버에 있고 작동하기 때문에 파일이 작동한다는 것을 알고 있습니다. 하지만 로컬에서는 작동하지 않는 것 같습니다.

찾을 수 있는 튜토리얼에 따라 모든 재정의를 설정했습니다. /etc/apache2/sites-available/default시작할 파일은 다음과 같습니다.

<VirtualHost *:80>
    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>

내 니블 사이트와 같은 디렉터리에 있는 코드는 다음과 같습니다.

<VirtualHost *:80>
    ServerName nibble.local
    DocumentRoot /var/www/nibble_framework/web/
    <Directory /var/www/nibble_framework/web/>
        AllowOverride All
        Options Indexes FollowSymLinks MultiViews
        Allow from All
    </Directory>
    RewriteLog /var/www/rewrite.log
    ErrorLog /var/log/apache2/error.log
</VirtualHost>

a2ensite를 사용하여 사이트를 활성화하고 Apache를 다시 시작했습니다. 또한 내 호스트 파일에 웹사이트를 추가했습니다.

  127.0.0.1  nibble.local

a2enmod를 사용하여 모드 재작성을 활성화하고 아파치를 여러 번 다시 시작/다시 로드했습니다.

  $ a2enmod rewrite 
  Module rewrite already enabled

.htaccess파일에는 이미 /var/www/nibble_framework/web/.htaccess다음 코드가 포함되어 있습니다.

  Options +FollowSymLinks +ExecCGI

  <IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^([^/]*)/?.*$ - [E=FILE:%{DOCUMENT_ROOT}/$1.php]

  RewriteCond %{ENV:FILE} !^$
  RewriteCond %{ENV:FILE} -f
  RewriteRule ^([^/]*)/?(.*)$ $1.php?url=$2 [QSA,L]

  RewriteCond %{ENV:FILE} !^$
  RewriteCond %{ENV:FILE} !-f
  RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
  </IfModule>

을 수행하면 print_r($_REQUEST)URL이 긴 문자열로 채워져 있어도 항상 빈 배열입니다.

이것이 왜 실패하는지 아는 사람이 있나요?

편집하다:

Apache2 액세스 로그:

~$ tail -f /var/log/apache2/access.log
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:39 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"
::1 - - [16/Aug/2011:07:32:40 +0100] "OPTIONS * HTTP/1.0" 200 152 "-" "Apache/2.2.16 (Ubuntu) (internal dummy connection)"

답변1

VirtualHost가 올바르게 처리되지 않아 요청 가져오기에 대해 AllowOverride가 설정되지 않는 것 같습니다. 먼저 /etc/hosts파일은 다음과 같아야 합니다.

127.0.0.1   localhost   localhost.localdomain
127.0.1.1   nibble.local

둘째, 이름 기반 가상 호스트에 대한 인터페이스를 설정해야 합니다. 현재 설정되어 있는지 지정하지 않았습니다. 일반적으로 기본 Apache 구성에 설정되어 있으며 ubuntu/debian이 이미 해당 파일을 찾은 것 같습니다 /etc/apache2/apache2.conf. 해당 행이 파일 어딘가에 설정되어 있는지 확인하십시오.

NameVirtualHost *:80

변경을 완료한 후 아파치를 다시 시작하세요.

sudo /etc/init.d/apache2 restart

아니요, 테스트해 보세요. 호스트 항목을 로컬에서만 설정한다는 점을 기억하세요. 따라서 이는 localhost에서 요청할 때만 올바르게 작동합니다. 막히거나 작동하지 않으면 관련 라인을 게시하십시오./var/log/apache2/error.log

답변2

.htaccess파일을 사용하려면 AccessFileName 지시문을 지정하십시오 .

AccessFileName .htaccess

다시 쓰기 엔진을 활성화하고 서비스를 다시 시작합니다.

sudo a2enmod rewrite 

관련 정보