简体   繁体   中英

Redirect subdomain to subfolder of main domain with same structure

Please help me to create rewrite rule for wordpress ( .htacess ) that will do the following:

Redirect subdomain

AAA.site.com/BBB.html to site.com/AAA/BBB.html

Let me explain here

  • I will create a subfolder(AAA) with same name as I have subdomain(AAA).
  • Page name remain unchanged(BBB.html)

I have more than 100+ subdomains which i want to redirect to the "folder" with same name as subdomain using WILDCARD.

Thanks in advance

Try this

RewriteEngine On
RewriteCond %{HTTP_HOST} ^\(.*\)\.site\.com$ [NC]
RewriteRule ^(.*)$ http://site.com/\1/$1 [L,R=301]

You can use mod_rewrite inside your .htaccess to do this.

RewriteEngine On

RewriteCond %{HTTP_HOST} ^aaa\.site\.com$ [NC]

RewriteRule ^(.*)$ http://site.com/aaa/$1 [L,R=301]

I think, this is what you are looking for:

RewriteCond %{HTTP_HOST} ^subdomain\.yourwebsite\.com$
RewriteCond %{REQUEST_URI} !^/subdomain_folder/
RewriteRule (.*) /subdomain_folder/$1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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