如何启用了mod_rewrite的Apache 2.2 [英] How to enable mod_rewrite for Apache 2.2

查看:159
本文介绍了如何启用了mod_rewrite的Apache 2.2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的Vista计算机上的Apache 2.2的全新安装,一切工作正常,但mod-rewrite。

I've got fresh install of Apache 2.2 on my Vista machine, everything works fine, except mod rewrite.

我已经取消注释

LoadModule rewrite_module modules/mod_rewrite.s

但没有我的重写规则的作品,即使是简单的像

but none of my rewrite rules works, even simple ones like

RewriteRule not_found %{DOCUMENT_ROOT}/index.php?page=404

我使用正在对我的主机的所有规则,所以他们应该是好了,我的问题是,有没有在Apache配置任何隐藏的东西,这可能会阻止mod-rewrite?

All the rules I'm using are working on my hosting, so they should be ok, so my question is, is there any hidden thing in apache configuration, that could block mod rewrite?

推荐答案

为了使用的mod_rewrite 您可以在终端上键入以下命令:

In order to use mod_rewrite you can type the following command in the terminal:

a2enmod rewrite

重启后的Apache2

Restart apache2 after

/etc/init.d/apache2 restart

service apache2 restart

然后,如果你愿意,你可以使用下面的的.htaccess 文件。

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
</IfModule>

以上的.htaccess 文件(如果放在你的的DocumentRoot )将所有流量重定向到的index.php 文件中的的DocumentRoot ,除非该文件存在。

The above .htaccess file (if placed in your DocumentRoot) will redirect all traffic to an index.php file in the DocumentRoot unless the file exists.

所以,让我们说你有以下目录结构,并上传至httpdocs是的DocumentRoot

So, let's say you have the following directory structure and httpdocs is the DocumentRoot

httpdocs/
    .htaccess
    index.php
    images/
        hello.png
    js/
        jquery.js
    css/
        style.css
includes/
    app/
        app.php

这是存在于httpdocs所有文件将使用显示的.htaccess 上面,但是,其他的一切都会被重定向到的httpdocs送达给请求者的index.php 。在您的应用程序文件包括/应用将无法访问。

Any file that exists in httpdocs will be served to the requester using the .htaccess shown above, however, everything else will be redirected to httpdocs/index.php. Your application files in includes/app will not be accessible.

这篇关于如何启用了mod_rewrite的Apache 2.2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆