Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
199 views
in Technique[技术] by (71.8m points)

apache - 如何为Apache 2.2启用mod_rewrite(How to enable mod_rewrite for Apache 2.2)

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

(我已经在我的Vista机器上安装了新的Apache 2.2,一切正常,除了mod重写。)

I've uncommented

(我没有注释)

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

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?

(我正在使用的所有规则都在处理我的托管,所以它们应该没问题,所以我的问题是,apache配置中是否有任何隐藏的东西,可以阻止mod重写?)

  ask by Jakub Arnold translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

(要使用mod_rewrite您可以在终端中键入以下命令:)

sudo a2enmod rewrite

Restart apache2 after

(之后重启apache2)

sudo /etc/init.d/apache2 restart

or

(要么)

sudo service apache2 restart

or as per new unified System Control Way

(或者按照新的统一系统控制方式)

sudo systemctl restart apache2

Then, if you'd like, you can use the following .htaccess file.

(然后,如果您愿意,可以使用以下.htaccess文件。)

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

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.

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

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

(所以,假设您有以下目录结构,httpdocs是DocumentRoot)

httpdocs/
    .htaccess
    index.php
    images/
        hello.png
    js/
        jquery.js
    css/
        style.css
includes/
    app/
        app.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 .

(httpdocs中存在的任何文件都将使用上面显示的.htaccess提供给请求者,但是,其他所有文件都将重定向到httpdocs/index.php 。)

Your application files in includes/app will not be accessible.

(您的应用程序文件includes/app将无法访问。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...