[英]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.