Формат Apache 2.4.6 default.conf изменен. Не удалось запустить .htaccess

Ребята. Я использую кодигнитер. Я использовал .htaccess, чтобы удалить «index.php» из моего URL-адреса, и добавил «Разрешить от всех» в мой default.conf. 'index.php' был успешно удален, и сайт заработал. Но с момента последнего обновления apache .htacess перестал работать, и в URL-адресах стал необходим «index.php». Это мой новый обновленный 000-default.conf.

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Я добавил следующие строки в свой 000-default.conf, но это не сработало:

AllowOverride all
Order allow,deny
Allow from all

Мой .htaccess в порядке, потому что до последнего обновления Apache он работал нормально.

Options -Indexes
RewriteEngine on

RewriteBase /
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_URI} ^htaccess/ [NC,OR]
RewriteCond %{REQUEST_URI} ^system/function/ [NC,OR]
#just make sure the last rule does  NOT have an OR
RewriteCond %{REQUEST_URI} ^system/class/ [NC]
RewriteRule . - [R=404,L,NC]

Моя версия апача 2.4.6. Теперь, пожалуйста, скажите мне, что добавить в 000-default.conf, чтобы заставить работать .htaccess и удалить «index.php» из URL-адреса моего сайта.

P.S. Я использую Ubuntu 12.04. mod_rewrite включен. Я включил 000-default.conf, т. е. он доступен в моей папке с поддержкой сайтов.


person CodeAddict    schedule 11.11.2013    source источник
comment
У вас есть файл /etc/apache2/apache2.conf? И в нем у вас есть строка AccessFileName .htaccess?   -  person jacouh    schedule 12.11.2013
comment
Да... У меня есть эта строка в моем apache2.conf.   -  person CodeAddict    schedule 13.11.2013


Ответы (3)


Я все еще новичок в мире сервера / командной строки, поэтому я подумал, что добавлю пошаговое решение для других в аналогичном месте. Надеюсь, это поможет кому-то:

  1. Войдите на свой сервер.

  2. Откройте файл 000-default.config с помощью nano:

    $ sudo nano /etc/apache2/sites-available/000-default.conf
    
  3. Найдите эту строку в VirtualHost: DocumentRoot /var/www/html и добавьте под ней следующее:

    <Directory /var/www >
        AllowOverride All
    </Directory> 
    
  4. Сохраните изменения: нажмите CTRL + O, чтобы записать; затем нажмите RETURN, чтобы сохранить изменения.

  5. Выйти из Nano: нажмите CTRL + X.

  6. Перезапустите ваш сервер:

    $ sudo service apache2 restart
    
  7. Если вам нужно активировать модуль apache mod_rewrite, выполните эту команду:

    $ sudo a2enmod rewrite 
    

    И если модуль уже активирован, вы получите сообщение о том, что все в порядке.

person KittenLogic    schedule 01.09.2014

Это немного устарело, но, поскольку я вижу это сейчас и заставил его работать, возможно, это прояснит всех, кто наткнулся на него.

Вы открываете этот файл 000-default.conf и находите, где он говорит «/var/www», а затем вставляете это:

<Directory /var/www>
AllowOverride All
</Directory>

Затем просто сохраните и перезапустите apache. Вам также необходимо включить mod_rewrite для Apache. Это легко найти в гугле.

person user3077947    schedule 07.12.2013

person    schedule
comment
Если бы вы могли дать более подробную информацию об этом, было бы здорово. - person ciprian; 24.11.2013