데비안에서는 URL 재작성이 작동하지 않습니다

데비안에서는 URL 재작성이 작동하지 않습니다

URL 재작성을 활성화하려고 하면 작동하지 않습니다. 명령을 사용하여 활성화 sudo a2enmod rewrite하고 sudo service apache2 restart. 그러나 루트 폴더 및 하위 폴더에서는 URL 다시 쓰기가 작동하지 않습니다.

추신: 다음 명령을 사용할 때 서버에서 다음 응답을 얻습니다 sudo a2enmod rewrite.

Module rewrite already enabled

요청 시:

<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>


    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
            AllowOverride all
            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

답변1

Apache2에는 기본적으로 mod_rewrite가 설치되어 있습니다. 이런 경우인지 확인하려면 /etc/apache2/mods-available/rewrite.load가 있는지 확인하세요.

      $ cat /etc/apache2/mods-available/rewrite.load

       LoadModule rewrite_module /usr/lib/apache2/modules/mod_rewrite.so

mod_rewrite를 활성화하고 로드하려면 나머지 단계를 따르세요.

      $ sudo a2enmod rewrite

위 명령은 /etc/apache2/mods-enabled에 심볼릭 링크를 생성합니다.

   $ ls -al /etc/apache2/mods-enabled/rewrite.load
  lrwxrwxrwx 1 root root 30 Dec  9 23:10   /etc/apache2/mods-enabled/rewrite.load -> ../mods-available/rewrite.load

그런 다음 다음 파일을 열고 "AllowOverride None"을 각각 "AllowOverride all"로 바꿉니다.

      $ sudo vi /etc/apache2/sites-available/default

마지막으로 Apache2를 다시 시작하십시오.

다음은 .htaccess 파일의 예입니다.

    Options +FollowSymlinks
    RewriteEngine On
    RewriteRule index.php / [L,R=301]

관련 정보