Reputation: 121
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!
Upvotes: 1
Views: 58
Reputation: 784898
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]
Upvotes: 1