apache.htaccess重写-我可以将其移动到httpd.conf中吗
下面是我在apache 2.2的apache.htaccess重写-我可以将其移动到httpd.conf中吗,apache,.htaccess,httpd.conf,Apache,.htaccess,Httpd.conf,下面是我在apache 2.2的.htaccess文件中仅有的代码 我已经读到,使用.htacess会对性能产生影响,如果可以在httpd.conf中使用它会更好。因此,我是否可以将其添加到httpd.conf?如果是的话,我会把它放在哪里 它是否需要进入每个需要它的主机(在我的例子中是许多主机)的VirtualHost,或者它是否可以进入httpd.conf以便应用于所有主机 <IfModule mod_rewrite.c> RewriteEngine on Rew
.htaccess
文件中仅有的代码
我已经读到,使用.htacess
会对性能产生影响,如果可以在httpd.conf
中使用它会更好。因此,我是否可以将其添加到httpd.conf
?如果是的话,我会把它放在哪里
它是否需要进入每个需要它的主机(在我的例子中是许多主机)的VirtualHost,或者它是否可以进入httpd.conf以便应用于所有主机
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-L
重写规则^(.*)$index.php?/$1[L]
每个VirtualHost都需要指定自己的重写规则,除非:
include
指令根据Apache文档,您可以将配置放在
-块中的.htaccess中
如果可以访问httpd主服务器配置文件,则应避免完全使用.htaccess文件。使用.htaccess文件会降低Apache http服务器的速度。可以包含在.htaccess文件中的任何指令最好在目录块中设置,因为它具有相同的效果和更好的性能
为了简化管理,我将把重写指令放在一个单独的文件中,然后包含在每个虚拟主机中。它应该可以工作。
.htaccess
提供目录配置,而httpd.conf提供总体配置。当然,您可以将内容从.htaccess
移动到httpd.conf
。
您可以在此处找到有关.htaccess的更多信息:
以.htaccess为例:
/www/htdocs/example中.htaccess文件的内容
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-L
重写规则^(.*)$index.php?/$1[L]
从httpd.conf文件中删除
<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>
重新启动发动机
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-L
重写规则^(.*)$index.php?/$1[L]
当然可以。引用上述网站的话:如果您有权访问httpd主服务器配置文件,则应避免完全使用.htaccess文件。使用.htaccess文件会降低Apache http服务器的速度。可以包含在.htaccess文件中的任何指令最好在目录块中设置,因为它具有相同的效果和更好的性能。