简体   繁体   English

htaccess-将查询字符串包含在重定向URL中

[英]htaccess - include the query string in the redirect URL

I have a website and I want to add a code line in the .htaccess file in order to redirect automaticaly the pages to another site. 我有一个网站,我想在.htaccess文件中添加代码行,以便将页面自动重定向到另一个站点。

Redirect
/index.php/component/virtuemart/XXXXX.html
https://www.trazeras.gr/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=XXXXX

The XXXXX ais a number which could have 1-5 digits The above number should be taken from the initial site url and to be used at the destination site url XXXXX是一个可以包含1-5位数字的数字。以上数字应取自初始站点网址,并在目标站点网址中使用

I tried the following code but it doesnt work 我尝试了以下代码,但没有用

# Redirect Query String
<IfModule mod_rewrite.c>
RewriteCond %{QUERY_STRING} ^/virtuemart/([0-9]+) [NC]
RewriteRule ^(.*)$ https://www.trazeras.gr/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=%1? [R=301,L]
</IfModule>

any thoughts? 有什么想法吗?

The URL doesn't have a query string, so you shouldn't redirect using it: 该网址没有查询字符串,因此您不应使用它进行重定向:

# Redirect Query String
<IfModule mod_rewrite.c>
RewriteRule ^/virtuemart/([0-9]+) https://www.trazeras.gr/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=$1 [NC,R=301,L]
</IfModule>

最后,这对我有用:

RewriteRule  ^(.*)virtuemart/([0-9]+).html$ https://www.trazeras.gr/index.php?option=com_virtuemart&view=productdetails&virtuemart_product_id=$2 [R=301,L] [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM