---
title: 自定义.htaccess文件 Rewrite
slug: rewrite-with-custom-htaccess
date: 2022-11-25
author: Frankie 徐
category: other
tags: []
description: Redirect 301 /html_info/Service.html /service/ Redirect 301 /e_aboutus/ /about-eco-drinkware/ Redirect 301 /e_contact/ /contact-us/ Redirect 301 /index_en.html / ...
permalink: https://www.210k.cc/rewrite-with-custom-htaccess
---

## 参考资料：

[https://httpd.apache.org/docs/current/rewrite/intro.html](https://httpd.apache.org/docs/current/rewrite/intro.html)

[https://httpd.apache.org/docs/current/mod/mod\_rewrite.html](https://httpd.apache.org/docs/current/mod/mod_rewrite.html)

插入到rewriteBase /之后

```
# 转发单个文件
Redirect 301 /html_info/Service.html /service/
Redirect 301 /e_aboutus/ /about-eco-drinkware/
Redirect 301 /e_contact/ /contact-us/
Redirect 301 /index_en.html /

# 只要是e_order文件夹里面的内容，不管是什么，通通转发到/inquire/
RewriteCond %{REQUEST_URI} ^\/e\_order\/(.*)
RewriteRule . /inquire/? [R=301,L]

# 转发任意两个文件夹：e_order或者e_feedback
RewriteCond %{REQUEST_URI} ^\/(e_order\/(.*))|(e_feedback\/(.*))
RewriteRule . /inquire/? [R=301,L]

# 一个文件夹下的多个网页，统一转发到/news/
# /e_news/
# /e_news/1-1.html
# /e_news/2-1.html

RewriteCond %{REQUEST_URI} ^\/e_news\/(.*)
RewriteRule . /news/? [R=301,L]

# 转发
# 原链接：/e_products/xxx.html
# 新链接：/e_products/xxx/  或者也可以任意自定义的文件夹，/也可以

RewriteCond %{REQUEST_URI} ^\/e_products\/(.*)\.html
RewriteRule .\/(.*)\.html /e_products/$1/? [R=301,L]

# 转发产品链接
# 原链接：/e_productshow/?xxxx.html
# /product/xxxx/
RewriteCond %{REQUEST_URI} /e_productshow/
RewriteCond %{QUERY_STRING} (.*)\.html
RewriteRule . /product/%1/? [R=301,L]

# 转发博客文章链接
# 原链接：/html_news/?xxxx.html
# /xxxx/
RewriteCond %{REQUEST_URI} /html_news/
RewriteCond %{QUERY_STRING} (.*)\.html
RewriteRule . /%1/? [R=301,L]
```