[英]htaccess redirect 301 all users from old folder with dash to newfolder, same domain
I want to move users who type or click on google results 我想移动输入或点击Google搜索结果的用户
http://example.com/name-lname/chicago
to 至
http://example.com/namelname/chicago
i tried 我试过了
Redirect 301 ^name-lname namelname
but i got error 500 how can i fix it? 但是我遇到错误500,我该如何解决?
尝试这个:
RewriteRule ^name-lname$ /namelname? [L,R=301]
You can use this rule as your very first rule in root .htaccess: 您可以将此规则用作根.htaccess中的第一个规则:
RedirectMatch 301 ^/name-lname(/.*)?$ /namelname$1
RedirectMatch
provides regex capability against Redirect
directive. RedirectMatch
提供针对Redirect
指令的正则表达式功能。
您需要使用RedirectMatch,因为重定向不支持regex:
RedirectMatch 301 ^/([^-]+)-([^/]+)/(.+)$ /$1$2/$3
For this kind of simple redirects, you do not need regexes, so you do not need mod_rewrite or RedirectMatch, simple Redirect is enough : 对于这种简单的重定向,您不需要正则表达式,因此您不需要mod_rewrite或RedirectMatch,简单的Redirect就足够了:
Redirect 301 /name-lname /namelname
Query strings and additionnal path parts will be added to the target URL. 查询字符串和附加路径部分将添加到目标URL。 From the doc :
来自doc :
Then any request beginning with URL-path (note: the /name-lname part) will return a redirect request to the client at the location of the target URL.
然后,任何以URL路径开头的请求(请注意:/ name-lname部分)都将在目标URL的位置向客户端返回重定向请求。 Additional path information beyond the matched URL-path will be appended to the target URL.
匹配的URL路径之外的其他路径信息将附加到目标URL。
But note that http://example.com/name-lnamefile.html
will not be matched. 但是请注意,
http://example.com/name-lnamefile.html
: http://example.com/name-lnamefile.html
将不匹配。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.