2

如果有人可以提供帮助,我将不胜感激。

我们有一个 CMS 在同一个托管包上运行 3 个网站(不同域上的国际版本),这些网站已经愉快地运行了一年多,没有任何问题,直到另一个我们对 .htaccess 文件进行了一些更改以制作 URL “更漂亮”。

该网站的结构是:

-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/) - 帖子与新闻相关联通过数据库中的页面 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

如果我解释得不够好,请告诉我。在此先感谢您的帮助。

4

1 回答 1

1

我没有看到任何使用数据库连接的指令。所以没有明显的原因导致额外的连接和 mysql 错误消息。

但是,如果它减慢整个系统的速度,它可能会导致连接保持打开更长时间。GET我用 Apache Bench (ab) 和一个简单的请求在我的系统上测试了你的规则。对于 10000 个请求,挂钟时间从 ~4.2 秒增加到 ~9.9 秒。

我肯定也会研究 PHP 并确认也没有更改。如果没有,您可以考虑使用数据库连接池(如果您还没有的话)。

由于您已经将所有内容放在单独的目录中,因此您还可以将 uk 移动到它自己的子目录,并将虚拟主机DocumentRoot设置为适当的子目录。然后您可以将特定的 htaccess 文件放在每个文档根目录中。这消除了对原始大小的测试%{HTTP_HOST}并将大小减少到大约三分之一。

此外,您可以将指令移动到虚拟主机上下文。这进一步减少了负载,因为 Apache 必须只读取和解析一次指令,而不是每次请求。

于 2013-04-23T14:13:56.633 回答