【发布时间】:2013-04-01 14:54:12
【问题描述】:
我刚刚在 godaddy 上托管了一个 wordpress 网站。
我有一个情况。
我有一个网站www.example.com/cn我希望当有人打开这个页面时这个页面应该重定向到一个子域cn.example.com。
我第一次托管 wordpress 应用程序,请让我知道我该怎么做。我是 Python Guy,我不知道 htaccess
我尝试在index.php 文件中使用header('location:cn.example.com'),但问题是cn.example.com 和example.com/cn 都指向同一个wordpress 应用程序。所以我遇到了问题。
请帮我解决这个问题。 *更新了 Htaccess *
RewriteCond %{REQUEST_URI} ^/_dm/s/ [NC,OR]
RewriteCond %{REQUEST_FILENAME} !\.(jpg|gif|png|css|js|txt|ico|pdf|bmp|tif|mp3|wav|wma|asf|mp4|flv|mpg|avi|csv|doc|docx|xls|xlsx|ppt|pptx|zip|rar|tar|gz|dmg|iso)$ [NC]
RewriteBase /
RewriteRule ^(.*)$ http://mobile.example.com/ [R,L]
##END MOBILE
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
谢谢
【问题讨论】:
-
如果两个域都托管在同一个 WordPress 安装中,您需要先启用多站点,然后才能使用不同的主机名。
-
哪里可以在 wp 中启用这个多站点?
-
您可以按照指南 here 进行操作 - 如果不启用它,WordPress 将针对任何不同的主机名重定向回
WP_HOME的值。通过将WP_HOME和WP_SITEURL动态设置为“欺骗” WorpPress 以考虑不同的主机名匹配,可能还有其他一些选择。然后,您可以在根目录下的.htaccess文件中使用mod_rewrite或使用 WordPress Rewrite API 进行重写