如果有人可以提供帮助,我将非常感激。
我们有一个CMS在同一个托管软件包上运行3个网站(在不同的域上的国际版本),这个软件包已经愉快地运行了一年多没有任何问题,直到另一个我们对.htaccess文件进行了一些更改才能使网址“更漂亮”。
网站的结构是:
-pages
-home.php <-- UK (www.site.com)
-your-basket.php <-- SSL (UK only)
-your-account.php <-- SSL (UK only)
-page.php
-sub pages etc
-de
-home.php <-- German (www.site.de)
-page.php
-sub pages etc
-it
-home.php <-- Italian (www.site.it)
-page.php
-sub pages etc
所有内容都从/ pages /开始,然后跟随结构,除了/ pages / posts /包含所有网站的新闻帖子(例如没有/ pages / de / posts /) - 帖子被绑定通过DB中的页面ID到新闻页面。
.htaccess的目的是完全从URL中删除/ pages /并使每个站点看起来像一个独立的站点,而不是在url中显示de / it子目录(例如www.site.de/page。 php而不是www.site.de/de/page.php)但是这是正确的还是有任何明显的错误可能导致循环或任何事情:
RewriteEngine On
ErrorDocument 404 /
ErrorDocument 500 /
#compress text
AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xhtml+xml
AddOutputFilterByType DEFLATE application/x-javascript application/javascript text/javascript text/css
FileETag none
<ifModule mod_php5.c>
php_value zlib.output_compression 16386
</ifModule>
#use cache
<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
ExpiresActive On
ExpiresDefault "access plus 1 year"
</FilesMatch>
### SSL specific redirects
#need to be placed before any other rewrites
# force https for basket and account pages
RewriteCond %{HTTPS} =off
RewriteRule ^(pages/your-basket|pages/your-account)\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# don't do anything for images/css/js (leave protocol as is)
RewriteRule \.(gif|jpe?g|png|css|js)$ - [NC,L]
# force http for all other URLs
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/(pages/your-basket|pages/your-account)\.php$
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
### Canonical redirect of home page
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /home-page\.php\ HTTP/
RewriteRule ^(.*)home-page\.php$ /$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /home\.php\ HTTP/
RewriteRule ^(.*)home\.php$ /$1 [R=301,L]
#set home pages - add home.php for international sites
DirectoryIndex index.php home.php
#### IT ####
# Redirect /it/ Requests - if subdir is present this removes it
RewriteCond %{THE_REQUEST} ^GET.*/it/ [NC]
RewriteCond %{HTTP_HOST} !^localhost(.+)$ [NC]
RewriteRule ^/?[^/]+/(.*)$ /$1 [L,R=301]
# Map http://www.site.it to /subdir.
RewriteCond %{HTTP_HOST} ^www.site.it$ [OR]
RewriteCond %{HTTP_HOST} ^site.it$
RewriteRule ^$ /pages/it/ [L]
# Map http://www.site.it/x to /subdir/x unless there is a x in the web root.
# If url does not contain "posts" execute to subdirectory
RewriteCond %{HTTP_HOST} ^www.site.it$ [OR]
RewriteCond %{HTTP_HOST} ^site.it$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !^GET.*/posts/ [NC]
RewriteCond %{REQUEST_URI} !^/pages/it/
RewriteRule ^(.*)$ /pages/it/$1
# Map http://www.site.it/x to /subdir/x unless there is a x in the web root.
# If url does contain "posts" rewrite to root
RewriteCond %{HTTP_HOST} ^www.site.it$ [OR]
RewriteCond %{HTTP_HOST} ^site.it$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET.*/posts/ [NC]
RewriteCond %{REQUEST_URI} !^/pages/
RewriteRule ^(.*)$ /pages/$1
#### DE ####
# Redirect /de/ Requests - if subdir is present this removes it
RewriteCond %{THE_REQUEST} ^GET.*/de/ [NC]
RewriteCond %{HTTP_HOST} !^localhost(.+)$ [NC]
RewriteRule ^/?[^/]+/(.*)$ /$1 [L,R=301]
# Map http://www.site.de to /subdir.
RewriteCond %{HTTP_HOST} ^www.site.de$ [OR]
RewriteCond %{HTTP_HOST} ^site.de$
RewriteRule ^$ /pages/de/ [L]
# Map http://www.site.de/x to /subdir/x unless there is a x in the web root.
# If url does not contain "posts" execute to subdirectory
RewriteCond %{HTTP_HOST} ^www.site.de$ [OR]
RewriteCond %{HTTP_HOST} ^site.de$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} !^GET.*/posts/ [NC]
RewriteCond %{REQUEST_URI} !^/pages/de/
RewriteRule ^(.*)$ /pages/de/$1
# Map http://www.site.de/x to /subdir/x unless there is a x in the web root.
# If url does contain "posts" rewrite to root
RewriteCond %{HTTP_HOST} ^www.site.de$ [OR]
RewriteCond %{HTTP_HOST} ^site.de$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{THE_REQUEST} ^GET.*/posts/ [NC]
RewriteCond %{REQUEST_URI} !^/pages/
RewriteRule ^(.*)$ /pages/$1
#### UK ####
# Map http://www.site.com to /subdir.
RewriteCond %{HTTP_HOST} ^www.site.com$ [OR]
RewriteCond %{HTTP_HOST} ^site.com$
RewriteRule ^$ /pages/ [L]
# Map http://www.site.com/x to /subdir/x unless there is a x in the web root.
RewriteCond %{HTTP_HOST} ^www.site.com$ [OR]
RewriteCond %{HTTP_HOST} ^site.com$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/pages/
RewriteRule ^(.*)$ /pages/$1
如果我没有充分解释,请告诉我。在此先感谢您的帮助。
答案 0 :(得分:1)
我没有看到任何使用数据库连接的指令。因此没有明显的原因导致其他连接和mysql错误消息。
但是,如果连接速度降低整个系统,可能会导致连接保持打开状态更长时间。我使用Apache Bench(ab)和一个简单的GET
请求在我的系统上测试了你的规则。对于10000个请求,挂钟时间从~4.2秒上升到~9.9秒。
我肯定会研究PHP,并确认没有更改。如果没有,您可以查看使用数据库连接池(如果尚未使用)。
由于您已将所有内容都放在不同的目录中,因此您还可以将uk移动到其自己的子目录中,并将DocumentRoot
设置为相应的子目录来设置虚拟主机。然后,您可以在每个文档根目录中放置特定的htaccess文件。这消除了%{HTTP_HOST}
的测试,并将大小缩小到原始大小的大约三分之一。
此外,您可以将指令移动到虚拟主机上下文。这进一步减少了负载,因为Apache必须只读取和解析指令一次而不是每次请求。