我有3个以上的网站,例如:
www.example.com/requestedpage
www.esempio.it/requestedpage
primer.ru/requestedpage
所有网站都指向同一服务器的目录。其中有3个目录:" en","它"," ru"其中包含本地化的请求页面。我想在内部将这些请求(仅PHP,而不是图像)重定向到文件夹而不更改URL。所以.com网站从" en"文件夹 - "它",ru - " ru"文件夹,但用户不应该看到它。
我尝试过一些东西,但它们不起作用..
RewriteCond ^(.+)\.(ru)$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/ru/$1 [NC,L]
RewriteCond %{HTTP_HOST} ^(.+)\.(ru)$
RewriteRule ^(.+)\.php$ ru%{REQUEST_URI} [NC,L]
RewriteCond %{HTTP_HOST} MYWEBSITE.ru$ [NC]
RewriteCond %{HTTP_HOST} !ru/
RewriteRule ^(.*)$ /ru/$1 [NC,L]
经过大量测试并感谢anubhava的帮助,我找到了一种方法来处理它,不是很好的方式,我认为应该改进:
# ===== MULTILANGUAGE WEBSITES =====
#Rule for IT website
RewriteCond %{HTTP_HOST} !ITALIANDOMAIN\.it$
RewriteRule .* - [S=3]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ it/$1/$2
RewriteRule ^([^/]+)$ it/$1
RewriteRule ^$ it/ [NC,L]
#Rule for FR website
RewriteCond %{HTTP_HOST} !FRANCEDOMAIN\.com$
RewriteRule .* - [S=3]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ fr/$1/$2
RewriteRule ^([^/]+)$ fr/$1
RewriteRule ^$ fr/ [NC,L]
#Rule for RU website
RewriteCond %{HTTP_HOST} !(RUSSIANDOMAIN1\.com)$
RewriteCond %{HTTP_HOST} !(xn--10-olc1a0ag\.xn--p1ai)$
RewriteRule .* - [S=3]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)$ ru/$1/$2
RewriteRule ^([^/]+)$ ru/$1
RewriteRule ^$ ru/ [NC,L]
答案 0 :(得分:0)
您可以在位于it, en, ru
个文件夹的父文件夹中的.htaccess中使用此规则:
RewriteEngine On
# skip all files and directories
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} \.(ru|it)$
RewriteCond %{REQUEST_URI} !^/(?:ru|it)/ [NC]
RewriteRule ^.*$ %1/$0 [L]
RewriteCond %{HTTP_HOST} \.com$
RewriteCond %{REQUEST_URI} !^/en/ [NC]
RewriteRule ^.*$ en/$0 [L]