我想知道,如果我将.htaccess文件内容移动到apache2的vhost文件中,是否可以提高性能?
这是我的.htaccess的内容
Options +FollowSymLinks +ExecCGI
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
如果这样做是个好主意,那么在vhost声明中,我应该把内容放在哪里?
谢谢!
发布于 2012-03-04 21:50:47
如果您可以编辑vhost-configuration文件,则应该始终这样做。向您的站点发出的每个请求都会解释.htaccess,而另一方面,vhost.conf只会在httpd重新启动/重新加载时解释。
您可以在目录指令中设置Options
,例如:
<Directory /usr/local/apache2/htdocs/somedir>
Options +FollowSymLinks +ExecCGI
</Directory>
<VirtualHost [...]>
[...]
RewriteEngine On
RewriteCond %{SERVER_NAME} ^([^.]+\.[^.]+)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]
# we check if the .html version is here (caching)
RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
# no, so we redirect to our front web controller
RewriteRule ^(.*)$ index.php [QSA,L]
</VirtualHost>
还要看看apache.org上的这个wikipost --特别是在什么情况下应该使用.htaccess文件,什么时候不应该使用这一部分?
https://stackoverflow.com/questions/6085222
复制相似问题