如果有人可以提供帮助,我将不胜感激。
我们有一个 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
如果我解释得不够好,请告诉我。在此先感谢您的帮助。