开发者

Can I use two separate browser-language-based RewriteCond's in .htaccess for root and subdomain

开发者 https://www.devze.com 2023-03-27 21:29 出处:网络
Can I use two separate browser-language-based RewriteCond\'s in .htaccess? One is for the domain root, one is for the subdomain \'m\'.

Can I use two separate browser-language-based RewriteCond's in .htaccess? One is for the domain root, one is for the subdomain 'm'.

RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /index_cz.php 开发者_开发百科[L,R=301]

RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /m/index_cz.html [L,R=301]

At the moment the first rule works fine, but the second rule does not appear to function and instead is showing the root index_cz.php if language 'cs' is found. Any ideas? Thanks!


RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /index_cz.php [L,R=301]

RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /m/index_cz.html [L,R=301]

your conditions are same! how apache should detect the difference!
If you want to use different languages, so change the conditions!

Edit:

RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteCond %{HTTP_HOST} www\.domain\.com [NC]
RewriteRule ^(.*)$ /index_cz.php [L,R=301]

RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteCond %{HTTP_HOST} m\.domain\.com [NC]
RewriteRule ^(.*)$ /m/index_cz.html [L,R=301]


Rules are parsed one after the other. Because of the 'L' instruction, as soon as a condition is fulfilled, the other rules are not checked, if my memory is good. This means you would have to add something to differentiate your conditions. When do you want each of the rewrite rules applied? Does 'm' stand for mobile? You are talking about a subdomain... You should then check for the subdomain too in the conditions.

If you really have an 'm' subdomain, what you mant might be the following rules:

RewriteCond %{HTTP_HOST} m.YourDomain.com [NC]
RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /m/index_cz.html [L,R=301]

RewriteCond %{HTTP_HOST} ([^.]+)\.YourDomain.com [NC]
RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /index_cz.php [L,R=301]

Don' forget to replace YourDomain.com by your actual domain name.

Does this help?


I forgot some characters in the domain checking. I should have written:

RewriteCond %{HTTP_HOST} ^m\.YourDomain\.com [NC]
RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /m/index_cz.html [L,R=301]

RewriteCond %{HTTP_HOST} ([^.]+)\.YourDomain\.com [NC]
RewriteCond %{HTTP:Accept-Language} (cs) [NC]
RewriteRule ^$ /index_cz.php [L,R=301]

I escaped the periods in the domain name and added a ^ at the beginning of the mobile subdomain. That sign means "starts with".

And you will need two extra sets of rules for English too.

0

精彩评论

暂无评论...
验证码 换一张
取 消