简体   繁体   English

网址的仅一部分需要被重定向301

[英]Only one part of url needs to be 301 redirected

I need to redirect on a bunch or URL's in my website. 我需要在我的网站上重定向一堆或URL。

I have http://www.myurl.lt/lt/imone/landstar-lt-lt/?cms_action=manage and I need to redirect it to http://www.myurl.lt/lt/imone/landstar-lt-lt/ 我有http://www.myurl.lt/lt/imone/landstar-lt-lt/?cms_action=manage ,我需要将其重定向到http://www.myurl.lt/lt/imone/landstar-lt -lt /

I have about 700 of them, so is it possible to do a redirect with one redirect command? 我大约有700个,因此是否可以使用一个redirect命令进行重定向?

This rules should remove the cms_action param, but preserve all other params 此规则应删除cms_action参数,但保留所有其他参数

RewriteCond %{QUERY_STRING} ^(.+?&|)cms_action=[^&]*(?:&(.*)|)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]

Place this rule in /it/imone/.htaccess file: 将此规则放在/it/imone/.htaccess文件中:

RewriteEngine On
RewriteBase /it/imone/

RewriteCond %{THE_REQUEST} /([^?]*)\?cms_action=manage [NC]
RewriteRule ^ %1/? [R=301,L]

RewriteCond %{QUERY_STRING} !(^|&)cms_action=manage(&|$) [NC]
RewriteRule ^ %{REQUEST_URI}?cms_action=manage [L,QSA]

Instead of using a Rewrite, which doesn't make any sense to me in this situation, why don't you just redirect the user directly from the manage action? 在这种情况下,我不使用“重写”对我没有任何意义,而是为什么不直接从管理操作中重定向用户呢? This will definitely add to clarity. 这肯定会增加清晰度。 If you were using PHP for example: 例如,如果您使用的是PHP:

// Inside manage action
header('Location: http://www.myurl.lt/lt/imone/landstar-lt-lt/');

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

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