`
hooroger
  • 浏览: 12745 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Enable mod_rewrite in a Ubuntu server

    博客分类:
  • php
阅读更多

If you have done much work with Apache then most likely you have experienced a need for enabling the rewrite engine. If you are unfamiliar with the rewrite engine, you can think of it as a means for your web server to literally rewrite urls so they are easier for users to remember. So instead of having to enter:

 

http://192.168.1.100/rewrite.php?link=1

 

Your users would only have to type:

 

http://192.168.1.100/link2.html

 

Of course the rewrite engine serves as much more than just a means for your users to more easily remember addresses. Many server softwares (such as the social networking server Elgg) depending upon the rewrite engine in order to function. Because of this, the rewrite engine is almost a necessity to have working. By default Apache does not have the rewrite engine on, so you have to configure it to work. The goal of this tutorial is to show you how to enable the rewrite engine in a Ubuntu server installation. This article will assume you already have your Ubuntu server as well as Apache up and running.

 

 

What this involves

 

In order to get the rewrite engine working for your web site you will have to take care of the following steps:

 

Instruct Apache to load the mod_rewrite module.

Edit the document root entry so that the rewrite engine is allowed.

Create an .htaccess file to rewrite urls for you.

 

Creating a simple test

 

Before we get to the actual configuration, the first thing to do is to set up a little rewrite test. Open up a terminal window (or log into your GUI-less server) and change to the /var/www directory. In that directory create a file, named rewrite.php, with the following contents. NOTE: Code is located on pastebin.com for ease of use.

 

Copy and paste the contents of that file into your rewrite.php file. If you visit that page, in a browser, without the rewrite engine working, you will quickly see that it will not work. So, let's get rewrite working.

 

Now you will have to create an .htaccess file in the /var/www/ directory with the following contents:

 

RewriteEngine On

RewriteRule ^link([^/]*).html$ rewrite.php?link=$1 [L]

 

Enabling the module

 

In order to enable the mod_rewrite module in the Ubuntu server issue the following command:

 

sudo a2enmod rewrite

 

The above Apache2 Enable Module command will add the correct line in the /etc/apache2/apache2.conf file. That is the only change you need to make with the apache2.conf file. Now it's time to make a change to the document root.

 

In older versions of Apache all virtual host directory directives were managed in the /etc/apache2/apache2.conf file. This has changed. Now these alterations are handled within the /etc/apache2/sites-enabled/ directory. Within that directory you will find, by default, a single file called 000-default. If you open that file up for editing you will see, at the top, the two sections you need to edit in order to enable the rewrite engine for the document root of your Apache server.

 

First look in the <Directory /> section and change the line:

 

AllowOverride None

 

to

 

AllowOverride All

 

Do the same for the <Directory /var/www/> section.

 

Once you have the file edited, restart Apache with the command:

 

sudo /etc/init.d/apache2 restart

 

Now revisit the rewrite.php page in your browser and you should see that rewriting is now working. Congratulations, you have just taken on step forward in opening up an entire world for your Apache needs.

 

Final thoughts

 

The rewrite engine is used by so many web-based tools. Upon installation of Apache, this should be one of the first tasks you tackle.

 

Enjoyed the article?: Then sign-up for our free newsletter or RSS feed to kick off your day with the latest technology news and tips, or share the article with your friends and contacts on Facebook, Twitter or Google+ using the icons below.

分享到:
评论

相关推荐

    MOD_REWRITE

    MOD_REWRITE

    ISAPI_Rewrite2.9版(有注册码)

    它的行为是像Apache的mod_Rewrite ,但专为微软的Internet信息服务( IIS ) 。 ISAPI_Rewrite是一个ISAPI筛选器的书面纯的C / C + +所以速度极快。 ISAPI_Rewrite让您的自由,超出标准网址计划和发展自己的计划。 ...

    ISAPI_Rewrite_full v2.9 完整注册版

    它非常类似于Apache's mod_Rewrite,但它是专为IIS设计的。 也是大家常说的URL 静态化了 ISAPI_Rewrite完全版:具有完整功能的版本(无任何限制)。 使用方法: 1、将下载文件解压安装,安装过程中你可以自己...

    ISAPI_Rewrite3完美破解版

    经测试过的ISAPI_Rewrite组件,可正常使用,已正常网站伪静态化及反向代理。

    ISAPI_Rewrite3_full完全版及绿色版

    2、在将Rewrite破解文件夹中的dll文件覆盖到程序安装目录下ISAPI_Rewrite.dll和ISAPI_RewriteSnapin.dll,如果提示在使用则把要覆盖的dll文件重命名在复制即可; 3、打开安装目录下的httpd.conf文件,在里面输入...

    ISAPI_Rewrite 3.1 Full版破解版

    ISAPI_Rewrite 3.1 Full版破解版 ISAPI_Rewrite是用来做什么的请大家自己去百度,我这里不作说明。 附件下载 uploadfile/ISAPI_Rewrite3_0067.msi(文件大小:3.42MB 下载次数:368) 这个软件不需要注册码就能用,...

    ISAPI_Rewrite3

    官方原版下载地址:http://www.helicontech.com/download/isapi_rewrite/ISAPI_Rewrite3_0087.msi 安装完官方版本后 把破解文件覆盖安装根目录 在根目录的httpd.conf 用文本编辑器打开编辑 RegistrationName= ...

    ISAPI_Rewrite3【伪静态】插件

    ISAPI_Rewrite3安装、使用方法(ISAPI_Rewrite3版本是3.1.0.73) 安装: 1、先从官网下一个完全版的ISAPI_Rewrite3(http://www.helicontech.com/download/isapi_rewrite/ISAPI_Rewrite3_0073.msi)并安装; 2、在...

    ISAPI_Rewrite3的安装和使用

    ISAPI_Rewrite3的安装和使用

    IIS7 windows2008 重写模块ISAPI_Rewrite3.msi

    ISAPI_Rewrite3_0104_x64.msi IIS7 windows2008 重写模块ISAPI_Rewrite3.msi

    isapi_rewrite 3.1.0.75 完整破解版(测试通过,绝对破解没有失效)

    1、用官方0075版本安装好以后,用ISAPI_Rewrite3_0075_cra文件下的两个文件覆盖安装路径下的原文件。 2、在安装目录下找到 httpd.conf 文件。输入以下内容: RegistrationName= coldstar RegistrationCode= 2EAD-...

    ISAPI_Rewrite3_0056.msi

    Apache的mod_rewrite功能可以说是相当的强大,其可以实现伪装静态URL以达到某些要求(譬如说SEO)。Wordpress也对此功能提供支持,在”设置-永久链接”中我们可以自定义永久链接结构。不过这一切都是基于mod_rewrite,...

    ISAPI_Rewrite3_0087注册码/ISAPI_Rewrite3_0087完美破解下载

    之前使用的ISAPI_Rewrite3_0082.msi访问比较大的时候会引起iis6应用程序池挂起,IIS自动停止,iis自动关闭,iis应用程序池无法开启,现在用ISAPI_Rewrite3_0087.msi能很好的解决这个问题。为大家献上最新ISAPI_...

    Mod_Rewrite_Automation:使用C2服务器前的mod_rewrite自动执行apache2站起来的脚本

    Apache Mod_Rewrite Terrafrom自动化 Bash脚本从用户那里获取变量,然后调用terraform脚本以在C2服务器之前使用mod_rewrite自动启动apache2。 现在,此仓库支持在Linode或Digital Ocean中站起来的重定向器,并且我有...

    IIS伪静态组件(支持多站点) ISAPI_Rewrite3.1_full0073和0087双版本完全DLL破解版

    重新上传ISAPI_Rewrite3.1_full完全DLL破解版。ISAPI_Rewrite3.1_0073和ISAPI_Rewrite3.1_0087这两个版本任选。 两个版本自己服务器亲测功能完全,破解完整。破解文件为两个DLL。 一、安装: 1、从官网原版下载...

    ISAPI_Rewrite3_0087 官方原版安装文件

    伪静态组件ISAPI_Rewrite3_0087官方原版安装文件。 到处都是破解文件,但原版安装文件找了好久才找到= =所以就传上来了···

    ISAPI_Rewrite3_0087完美破解

    安装完官方版本后 把破解文件覆盖安装根目录 在根目录的httpd.conf 用文本编辑器打开编辑 RegistrationName= WWWWANG_Panda RegistrationCode= 2EAD-35GH-66NN-ZYBA

    ISAPI_Rewrite.dll

    ISAPI_Rewrite 用IIS处地址转向

    mod_rewrite - Apache HTTP服务器.pdf

    mod_rewrite - Apache HTTP服务器.pdf

    php检测apache mod_rewrite模块是否安装的方法

    * @title Check if Apache's mod_rewrite is installed. * * @author Pierre-Henry Soria * @copyright (c) 2013, Pierre-Henry Soria. All Rights Reserved. * @return boolean */ function isRewriteMod() ...

Global site tag (gtag.js) - Google Analytics