【问题标题】:Virtual subdomains using .htaccess使用 .htaccess 的虚拟子域
【发布时间】:2015-04-16 07:48:23
【问题描述】:

我正在尝试使用 .htaccess 和 wordpress 创建虚拟子域。 但它似乎无法正常工作。使用 wordpress 我得到如下网址: foo.eu/test-pagina/?lang=fr

我设法将其重写为我想要的: fr.foo.eu/test-pagina/

但是当这个 url 被重写时,页面返回 500 内部服务器错误。

我还在我的 dns 配置中为子域设置了通配符。

我必须为我的根目录中的每个子域创建子文件夹吗?

我当前的 .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>

谁能告诉我我做错了什么?

【问题讨论】:

    标签: wordpress apache .htaccess mod-rewrite subdomain


    【解决方案1】:

    您是否在域的控制面板中添加了“fr”作为子域?

    将此添加到您的 htaccess 中

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

    【讨论】:

    • 是的,我已将 fr.foo.eu 添加为子域
    • 如果你只是转到 fr.foo.eu 会发生什么?
    • 然后还显示:500 internal server error。但是当我 ping fr.foo.eu 时奇怪的是它只是用正确的包回复。
    • 抱歉,我对 htaccess 不太擅长,我已经进行了编辑,您可以尝试一下,但我不确定它是否会起作用。这是一个非常相似的问题stackoverflow.com/questions/19348615/…
    猜你喜欢
    • 2012-07-11
    • 2012-10-03
    • 2011-03-30
    • 1970-01-01
    • 2023-04-10
    • 1970-01-01
    • 2014-02-07
    • 2011-03-28
    • 1970-01-01
    相关资源
    最近更新 更多