Home .htaccess URL redirect for sub domain
Reply: 1

.htaccess URL redirect for sub domain

Vito
1#
Vito Published in 2018-02-09 10:46:32Z

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&param=1 

redirect to

https://sub.example.com/app/?r=dl/catalog/show&param=1 

Thank you!

anubhava
2#
anubhava Reply to 2018-02-09 11:28:43Z

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]

References:

  • Apache mod_rewrite Introduction
  • Apache mod_rewrite Technical Details
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.328226 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO