且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

.htaccess 将文件夹重定向到一个 url

更新时间:2022-12-09 11:46:31

默认情况下,Redirect 将路径节点映射到一个新的路径节点,因此之后的任何内容第一个路径被附加到目标 URL.

试试:

RedirectMatch 301 ^/abc/cba/http://www.aaa.com/?

或者,如果您更愿意使用 mod_rewrite 而不是 mod_alias:

RewriteEngine On重写规则 ^/?abc/cba/http://www.aaa.com/?[R=301,L]

I'm trying to redirect a folder and all its sub files to a URL with a .htaccess file.

But

Redirect 301 /abc/cba/ http://www.aaa.com/

Will make /abc/cba/ddd/index.html redirect to http://www.aaa.com/ddd/index.html

What I want is redirect /abc/cba/ /abc/cba/ddd/index.html to http://www.aaa.com/

Could anyone help? Thanks. If anything not clear, please let me know.

By default, Redirect sort of maps the path node to a new path node, so anything after the first path gets appended to the target URL.

Try:

RedirectMatch 301 ^/abc/cba/ http://www.aaa.com/?

Or if you'd rather use mod_rewrite instead of mod_alias:

RewriteEngine On
RewriteRule ^/?abc/cba/ http://www.aaa.com/? [R=301,L]