[英]htaccess redirect 301 all users from old folder with dash to newfolder, same domain
我想移動輸入或點擊Google搜索結果的用戶
http://example.com/name-lname/chicago
至
http://example.com/namelname/chicago
我試過了
Redirect 301 ^name-lname namelname
但是我遇到錯誤500,我該如何解決?
嘗試這個:
RewriteRule ^name-lname$ /namelname? [L,R=301]
您可以將此規則用作根.htaccess中的第一個規則:
RedirectMatch 301 ^/name-lname(/.*)?$ /namelname$1
RedirectMatch
提供針對Redirect
指令的正則表達式功能。
您需要使用RedirectMatch,因為重定向不支持regex:
RedirectMatch 301 ^/([^-]+)-([^/]+)/(.+)$ /$1$2/$3
對於這種簡單的重定向,您不需要正則表達式,因此您不需要mod_rewrite或RedirectMatch,簡單的Redirect就足夠了:
Redirect 301 /name-lname /namelname
查詢字符串和附加路徑部分將添加到目標URL。 來自doc :
然后,任何以URL路徑開頭的請求(請注意:/ name-lname部分)都將在目標URL的位置向客戶端返回重定向請求。 匹配的URL路徑之外的其他路徑信息將附加到目標URL。
但是請注意, http://example.com/name-lnamefile.html
: http://example.com/name-lnamefile.html
將不匹配。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.