How can I redirect all queries from sub folder to sub domain with .htaccess?
Including query string (after "/?").
And this should be friendly for SEO (generates 301).
Example:
https://example.com/app/?r=dl/catalog/show¶m=1
redirect to
https://sub.example.com/app/?r=dl/catalog/show¶m=1
Thank you!
Inside app/.htaccess
you can use this rule:
RewriteEngine On
# works on Apache 2.4+
RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$ [NC]
RewriteRule ^ %{REQUEST_SCHEME}://sub.%1%{REQUEST_URI} [L,R=301,NE]
If you're using older Apache 2.2 then use this rule instead:
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://sub.example.com%{REQUEST_URI} [L,R=301,NE]
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.