Move .htaccess content into vhost, for performance

前端 未结 1 835
孤独总比滥情好
孤独总比滥情好 2020-12-15 21:25

I was wondering if performance can be increased if I move .htaccess file content into a vhost file of apache2?

This is the content of my .htaccess

O         


        
相关标签:
1条回答
  • 2020-12-15 21:43

    If you have the possibility to edit vhost-configuration file(s) you should always do so. The .htaccess is getting interpreted with every single request which is made to your site while on the other hand the vhost.conf is only interpreted on httpd restart/reload.

    You could set the Options in Directory-directive - e.g.:

    <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>
    

    Also take a look at this wikipost on apache.org - especially the section When should I, and should I not use .htaccess files?

    0 讨论(0)
提交回复
热议问题