zoukankan      html  css  js  c++  java
  • Linux下 rewrite_mod 的配置


    以下使用最新的 Ubuntu 16.04 测试;

    安装好apache后先确认有没有rewrite模块,大多数情况下是有的;
    ls /etc/apache2/mods-available |grep rewrite
    没有的话:
    apt install libapache2-mod-rewrite

    在确认rewrite模块是否开启了
    ls /etc/apache2/mods-enabled |grep rewrite
    如果没有开启模块,可以手动开启
    a2enmod rewrite

    修改apache配置文件允许重写;
    vim /etc/apache2/apache2.conf
    看到类似这样的一段:
    <Directory /path/to/your/website>
            Options Indexes FollowSymLinks
            AllowOverride None
            Require all deny
    </Directory>
    改为:
    <Directory /path/to/your/website>
            Options Indexes FollowSymLinks
            AllowOverride All    #允许重写
            Require all granted     #允许所有访问来源
    </Directory>

    还有这个地方:
    <FilesMatch "^.ht">
            Require all deny
    </FilesMatch>

    改为( .htaccess 才能生效):
    <FilesMatch "^.ht">
            Require all granted
    </FilesMatch>

    所有东西完成后,重启apache;

    /etc/init.d/apache2 restart

    确保上面的工作已经完成了,现在开始讲路由重写;

    在网站根目录创建 .htaccess 文件 (通常不要直接把路由规则写到apache.conf)

    开启重写引擎
    RewriteEngine On
    重写的起始目录
    RewriteBase

  • 相关阅读:
    设计规范理解
    JVM读书笔记
    springboot整合RabbitMQ
    springboot 整合Redis
    tomcat原理
    配置嵌入式Servlet容器
    Springboot自动配置原理
    Springboot启动原理
    Springboot配置文件加载顺序
    修改VisualSVN Server地址为ip地址,修改svn服务端地址为ip或者域名地址的方法
  • 原文地址:https://www.cnblogs.com/codeAB/p/6337007.html
Copyright © 2011-2022 走看看