Apacheリダイレクト301親ディレクトリが機能しません。

Apacheリダイレクト301親ディレクトリが機能しません。

2つの同様のパスを同じWebページにリダイレクトする必要があります。

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/

おすすめ記事