I want to move users who type or click on google results
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?
尝试这个:
RewriteRule ^name-lname$ /namelname? [L,R=301]
You can use this rule as your very first rule in root .htaccess:
RedirectMatch 301 ^/name-lname(/.*)?$ /namelname$1
RedirectMatch
provides regex capability against Redirect
directive.
您需要使用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 :
Redirect 301 /name-lname /namelname
Query strings and additionnal path parts will be added to the target URL. From the 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. Additional path information beyond the matched URL-path will be appended to the target URL.
But note that http://example.com/name-lnamefile.html
will not be matched.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.