简体   繁体   English

WordPress的:重定向URL到一个子域

[英]Wordpress : redirect url to a subdomain

I have just hosted a wordpress website on godaddy . 我刚刚在godaddy上托管了一个wordpress网站。

I am having a situation . 我有一个情况。

I have a website www.example.com/cn I want when someone open this page this page should redirect to a sub domain cn.example.com . 我有一个网站www.example.com/cn当有人打开此页面时,我希望此页面应重定向到子域cn.example.com

I am hosting wordpress app first time kindly do let me know how can I do that .I am Python Guy I don't know about htaccess 我是第一次托管wordpress应用,请告诉我该怎么做。我是不知道htaccess Python Guy。

I tried using header('location:cn.example.com') in the index.php file but the problem is cn.example.com and example.com/cn both pointed to the same wordpress app . 我尝试在index.php文件中使用header('location:cn.example.com') ,但问题是cn.example.comexample.com/cn都指向同一个wordpress应用。 So I am getting problem . 所以我遇到了问题。

Please help me to figure out this problem . 请帮我找出这个问题。 * Updated Htaccess * * 更新的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

Thanks 谢谢

Assuming you are letting Wordpress load from the differing hostname, you can handle the rewrite by having the following in your .htaccess file found in the root of your Wordpress install: 假设您允许从不同的主机名加载Wordpress,则可以通过在Wordpress安装根目录下的.htaccess文件中包含以下内容来处理重写:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} (?!cn.example.com)
RewriteRule ^cn/?$ http://cn.example.com/ [R=301,L]

It will match /cn or /cn/ exactly from any host that is not already cn.example.com (prevent looping), and redirect to http://cn.example.com using a 301 HTTP response. 它将匹配/cn/cn/恰好从不是已经任何主机cn.example.com (防止循环),并重定向到http://cn.example.com使用301的HTTP响应。

You can test these rules here: http://htaccess.madewithlove.be/ 您可以在此处测试这些规则: http : //htaccess.madewithlove.be/

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

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