[英].htaccess URL redirect for sub domain
How can I redirect all queries from sub folder to sub domain with .htaccess?如何使用 .htaccess 将所有查询从子文件夹重定向到子域?
Including query string (after "/?").包括查询字符串(在“/?”之后)。
And this should be friendly for SEO (generates 301).这应该对 SEO 友好(生成 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:在
app/.htaccess
您可以使用以下规则:
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:如果您使用的是较旧的 Apache 2.2,请改用此规则:
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://sub.example.com%{REQUEST_URI} [L,R=301,NE]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.