Ubuntu下Apache开启Rewrite伪静态並禁止目录浏览 - konakona
konakona
Dream Afar.
konakona

Ubuntu下Apache开启Rewrite伪静态並禁止目录浏览

终端运行:

sudo a2enmod rewrite     #开启Rewrite模块

sudo /etc/init.d/apache2 restart     #重启apache

 

然後開始修改網站配置,如果你只有一個網站,使用的是默認配置,則配置地址是/etc/apache2/sites-enabled/000-default

sudo gedit /etc/apache2/sites-enabled/000-default     #修改以下地方

Options FollowSymLinks

AllowOverride None(修改为AllowOverride All)

Options Indexes FollowSymLinks MultiViews

AllowOverride None(修改为AllowOverride All)

Order allow,deny

allow from all

 

修改AllowOverride的意義在於讓apache識別.htaccess.

 

禁止目錄訪問的方法是將Options裡添加一句 “-Indexes”,像這樣:

Options -Indexes FollowSymlinks

 

然後:

sudo /etc/init.d/apache2 restart     #重启apache

 

在网站根目录下面建立.htaccess文件:

sudo touch .htaccess

 

修改.htaccess文件属性:

sudo chmod 755 .htaccess

修改.htaccess文件:

sudo gedit .htacess

在空白的.htaccess文件中,写入如下内容:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
</IfModule>

 

赞赏
#
首页      程序开发      Linux      Ubuntu下Apache开启Rewrite伪静态並禁止目录浏览

团哥

文章作者

继续玩我的CODE,让别人说去。 低调,就是这么自信。

konakona

Ubuntu下Apache开启Rewrite伪静态並禁止目录浏览
终端运行: sudo a2enmod rewrite     #开启Rewrite模块 sudo /etc/init.d/apache2 restart     #重启apache   然後開始修改網站配置,如果你只有一個網站,使用的是默認配…
扫描二维码继续阅读
2012-11-14