2015-09-06 119 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