我需要将 2 个相似的路径重定向到同一网页,es
http://www.domain.com/foo-->http://www.domain.com/ok
http://www.domain.com/foo/bar-->http://www.domain.com/ok
我在 .htaccess 中有这个:
Redirect 301 /foo http://www.domain.com/ok
Redirect 301 /foo/bar http://www.domain.com/ok
如果我去http://www.domain.com/foo重定向有效,如果我去http://www.domain.com/foo/bar, 我有http://www.domain.com/ok/bar但它不起作用。如何解决这个问题?
答案1
尝试更改顺序:
Redirect 301 /foo/bar http://www.domain.com/ok
Redirect 301 /foo http://www.domain.com/ok
另请参阅 mod_rewrite:
http://httpd.apache.org/docs/current/mod/mod_alias.html
#With mod_rewrite
RewriteEngine on
RewriteRule ^/docs/(.+) http://new.example.com/docs/$1 [R,L]
#With RedirectMatch
RedirectMatch ^/docs/(.*) http://new.example.com/docs/$1
#With Redirect
Redirect /docs/ http://new.example.com/docs/