简体   繁体   English

使用.htaccess的虚拟子域

[英]Virtual subdomains using .htaccess

I am trying to create virtual subdomains using .htaccess and wordpress. 我正在尝试使用.htaccess和wordpress创建虚拟子域。 But it won't seem to work properly. 但它似乎无法正常工作。 Using wordpress I get urls like: foo.eu/test-pagina/?lang=fr 使用wordpress,我得到如下URL:foo.eu/test-pagina/?lang=fr

I managed to rewrite this to what i want: fr.foo.eu/test-pagina/ 我设法将其重写为我想要的:fr.foo.eu/test-pagina/

But when this url is rewritten the page returns an 500 internal server error. 但是,当重写此url时,页面将返回500内部服务器错误。

I also made a wildcard for the subdomains in my dns configuration. 我还在dns配置中为子域设置了通配符。

Do I have to make subfolders for each subdomain in my root ? 我必须为根目录中的每个子域创建子文件夹吗?

My current .htaccess code is: 我当前的.htaccess代码是:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{HTTP_HOST} !^([a-z]{2})\.hypnose\.eu$ [NC]
RewriteCond %{THE_REQUEST} \ /+([^\?]*)\?lang=([a-z]{2})&?([^\ ]*)
#RewriteRule ^ http://%2.hypnose.eu/%1?%3 [L,R]

RewriteCond %{QUERY_STRING} !(^|&)lang=
RewriteCond %{HTTP_HOST} ^([a-z]{2})\.hypnose\.eu$ [NC]
RewriteRule ^(.*)$ /$1?lang=%1 [L,QSA]

RewriteRule ^index\.php$ - [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]
</IfModule>

Can anyone tell me what did I do wrong? 谁能告诉我我做错了什么?

Have you added "fr" as your subdomain in the domain's control panel? 您是否已在域的控制面板中将“ fr”添加为子域?

Add this in your htaccess 将此添加到您的htaccess中

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/test-pagina/%1/$1 [L,NC,QSA]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM