mod_rewrite%{REQUEST_URI}将domain.com/category重定向到category.domain.com

时间:2017-12-19 15:03:53

标签: apache redirect mod-rewrite

我正在尝试重定向

https://www.example.com/category/及其所有子类别和内容 https://category.example.com

所以最后我得到了例如

https://category.example.com/subcategory/content=xyz;param=1

重定向
https://www.example.com/category/subcategory/content=xyz;param=1

我在这里尝试了很多来自其他线程的建议,但只得到了

 https://www.example.com/category/subcategory/content=xyz;param=1
 https://category.example.com/

https://www.example.com/category/subcategory/content=xyz;param=1
https://category.example.com/category/subcategory/content=xyz;param=1

工作。 我认为这是我的正则表达式,但我不确定。我的配置是

RewriteEngine On
RewriteLog /var/log/vgn_rewrite.log
RewriteLogLevel 5
RewriteCond %{HTTP_HOST} !category.example.com$ [NC] [OR]
RewriteCond %{REQUEST_URI} ^(.*)/category/(.*)$
RewriteRule ^/(.*)$ https://category.example.com$1 [R=301,L]

2 个答案:

答案 0 :(得分:1)

你可以试试这个:

RewriteEngine On

RewriteRule ^category/(.*)/(.*)$ https://category.yourwebsite.com/$1/$2 [R=301,L]

答案 1 :(得分:0)

找到解决方案。我认为我的所有尝试都变得复杂了。

RewriteEngine On
RewriteCond %{HTTP_HOST} !category.example.com$ [NC]
RewriteRule ^/category(.*)$ https://category.example.com$1 [QSA,R=301,L]

终于来了! 谢谢你的帮助!