apache .htaccess重写-我可以将其移到httpd.conf中吗 [英] apache .htaccess rewrite - can I move this into httpd.conf

查看:103
本文介绍了apache .htaccess重写-我可以将其移到httpd.conf中吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是我在Apache 2.2中的 .htaccess 文件中唯一的代码。

Below is the only code I have in the .htaccess file with apache 2.2.

我已经读到使用 .htacess 会对性能产生影响,如果可以运行,效果会更好从 httpd.conf 中删除​​。因此,是否可以将其添加到 httpd.conf 中?如果是这样,我会放在哪里?

I've read that its a performance impact to use a .htacess and better if this this can be run out of httpd.conf. Therefore is it possible for me to add this into httpd.conf? If so where would I put it?

是否需要为每个需要它的主机(在我的情况下为很多主机)进入VirtualHost,或者可以通用地进入httpd.conf以便应用

Would it need to go into the VirtualHost for each Host that needed it (in my case a lot of hosts) or could it go generically into httpd.conf so it applies to all hosts?

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


推荐答案

.htaccess 提供目录的配置,而httpd.conf提供整体配置。当然,您可以将内容从 .htaccess 移到 httpd.conf
您可以在此处找到有关.htaccess的更多信息: Apache HTTP Server教程:.htaccess文件

.htaccess provides configuration for a directory, while httpd.conf provides an overall configuration. Of course, you can move content from .htaccess to httpd.conf. You can find more about .htaccess here: Apache HTTP Server Tutorial: .htaccess files

以您的.htaccess为例:

Take your .htaccess for example:

/ www / htdocs / example中.htaccess文件的内容

Contents of .htaccess file in /www/htdocs/example

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

您的httpd.conf文件中的部分

Section from your httpd.conf file

<Directory /www/htdocs/example>
    <IfModule mod_rewrite.c>
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{REQUEST_FILENAME} !-l
        RewriteRule ^(.*)$ index.php?/$1 [L]
    </IfModule>
</Directory>

这篇关于apache .htaccess重写-我可以将其移到httpd.conf中吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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