大网数据广告活动
网站运营与故障问答

change DirectoryIndex file for subdomain

· 52CE 我爱测

I want two languages on my website - one french-specific website, and one in english for broader purposes (and no automatic translation). For maintenance reasons, I'd like to not duplicate images and CSS, ... I also set up subdom…

问题原文

原帖链接 · luneart · CC BY-SA 4.0

I want two languages on my website - one french-specific website, and one in english for broader purposes (and no automatic translation). For maintenance reasons, I'd like to not duplicate images and CSS, ... I also set up subdomains for language variants - for now both point to the www folder of my domain.

So I have two "index.htm" and "index_fr.htm" files, and a "fr" subdomain.

I've read up a bit about htaccess, and I'd like to set one up so that DirectoryIndex index_fr.htm is triggered when accessed through the subdomain.

Is it feasible? does it make sense? and how?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

I don't see as you necessarily need to change the DocumentRoot of the subdomain (as discussed in comments), since you want to "share images and CSS" between language versions.

However, changing the DirectoryIndex is probably not what you want to do either.

Instead, use mod_rewrite to internally rewrite the request to /index_fr.htm when requesting the document root of the subdomain.

For example, in your root .htaccess file:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^fr\.example\.com [NC]
RewriteRule ^$ index_fr.htm [L]

This is essentially the equivalent of conditionally setting DirectoryIndex.

If you request https://fr.example.com/ then you'll be internally redirected to /index_fr.htm. Otherwise the normal DirectroryIndex will be served.

However, it's not clear how you want to handle requests of the form https://fr.example.com/foo? The above directive does not cover that.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2020-04-21)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。