如何在不影响 apache 中的文件的情况下重定向文件夹?
How to redirect folder without affecting its files in apache?
我的 .htaccess
文件中有以下重写规则:
Redirect 301 /products http://example.com/products.html
效果很好,但它会影响文件夹内文件的 URL,因此:
http://example.com/products/item.html
重定向到:
http://example.com/products.html/item.html
有什么方法可以让我的重定向只针对父文件夹而不是其中的文件?
Is there any way that I can only target the parent folder with my redirect and not the files inside it?
是,使用 RedirectMatch
使用 regex 进行精确定位:
RedirectMatch 301 ^/products/?$ http://example.com/products.html
正则表达式 ^/products/?$
将匹配 /product
或 /product/
但不匹配 /product/file
.
我的 .htaccess
文件中有以下重写规则:
Redirect 301 /products http://example.com/products.html
效果很好,但它会影响文件夹内文件的 URL,因此:
http://example.com/products/item.html
重定向到:
http://example.com/products.html/item.html
有什么方法可以让我的重定向只针对父文件夹而不是其中的文件?
Is there any way that I can only target the parent folder with my redirect and not the files inside it?
是,使用 RedirectMatch
使用 regex 进行精确定位:
RedirectMatch 301 ^/products/?$ http://example.com/products.html
正则表达式 ^/products/?$
将匹配 /product
或 /product/
但不匹配 /product/file
.