Ubuntu: 开启apache地址重写, rewrite, Enabling .htaccess file to rewrite path, .htaccess – URL rewriting not working, Rewrite rules not working

 

  1. sudo vi /etc/apache2/apache2.conf  (没有的话,可以尝试sudo vi /etc/apache2/sites-available/000-default.conf)打开apache配置文件
    <Directory /var/www/>  #实际目录根据网站根目录而定
    
        Options Indexes FollowSymLinks
        AllowOverride None  #改为All
        Require all granted
    
    </Directory>
    
  2.  执行命令:sudo a2enmod rewrite
  3. 在网站的根目录下建立.htaccess文件,内容为:
    <IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>
  4. 重启apache服务。。必须是root才能重启,可以使用命令:sudo service apache2 restart 或者 sudo service apache2 reload

 

本文:Ubuntu: 开启apache地址重写, rewrite, Enabling .htaccess file to rewrite path

Loading

Add a Comment

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.