2015-09-06 49 views
0

类似的重复关键字我有这个网址:移除/删除从URL的htaccess

http://www.domain.net/iphone-reparatur-bremen/iphone-6-**reparatur** 

,并希望这样的:

http://www.domain.net/iphone-**reparatur**-bremen/iphone-6 

我有很多链接(200+)这样的。

如何从url中删除最后一个单词“reparatur”?

Options +FollowSymLinks 
RewriteEngine On 

RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR] 
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR] 
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR] 
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
RewriteRule .* index.php [F] 

RewriteBase/

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 
RewriteCond %{REQUEST_URI} !^/index\.php 

RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule .* index.php [L] 

RewriteCond %{HTTP_HOST} (www\.)xn--domain-3ya.de 
RewriteRule (.*) http://www.domain.de [L,R=301] 

RewriteRule ^([^-/]+-([^/-]+)-[^/]+/.+?)-\2\b /$1 [NC,L,R=302] 
#RewriteRule ^(iphone-([^/]+)-[^/]+/iphone-\d)-\2\b /$1 [NC,L,R=302] 

RewriteCond %{QUERY_STRING} ^_=([^&]*) [NC] 
RewriteRule^%{REQUEST_URI}?.html=%1 [R,L] 



#Für weiterleitung von/auf root 
Redirect 301 /de/ http://www.domain.de/ 

#haupt-kategorien 
Redirect 301 /handy http://www.domain.de 
Redirect 301 /handy-reparatur http://www.domain.de 
Redirect 301 /handy-reparatur-bremen http://www.domain.de 

而且有很多301 .. ignoremeignoremeignoremeignoremeignoremeignoremeignoreme

回答

0

您可以使用此回参考基础的规则来查找和您的规则删除重复的部分。将这个规则在你的根的.htaccess:

RewriteEngine On 

RewriteRule ^([^-/]+-([^/-]+)-[^/]+/.+?)-\2\b /$1 [NC,L,R=302] 

据初步/iphone-后获取价值,并在此子模式([^/]+)分组。后来在正则表达式中,它使用了反向引用\2来确保相同的捕获值最终。

\b用于文字边界。

这将重定向:

/iphone-reparatur-bremen/iphone-6-reparatur => /iphone-reparatur-bremen/iphone-6 
/iphone-foobar-something/iphone-6-foobar => /iphone-foobar-something/iphone-6 
+0

真的感谢快速回复!我测试了它,但没有奏效。我有不同的网址,比如像“www.domain.net/samsung-reparatur-bremen/samsung-galaxy-s5-mini-reparatur” – recep779

+0

没有人missunderstand:D我说'它不起作用'... :) – recep779

+0

好吧现在尝试我的更新规则。 – anubhava