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

问题描述 投票:0回答:2

我正在尝试重定向

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]
apache redirect mod-rewrite
2个回答
1
投票

你可以试试这个:

RewriteEngine On

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

0
投票

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

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

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

© www.soinside.com 2019 - 2024. All rights reserved.