重定向站点的.htaccess,但不包括一个文件夹 [英] Redirect site with .htaccess but exclude one folder

查看:237
本文介绍了重定向站点的.htaccess,但不包括一个文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要301重定向整个网站,但不包括一切名为上传文件夹中存在的根目录中。 我用Google搜索了这一点,但并没有拿出任何东西,否则我不认为我所看到的是对的。

I want to 301 redirect an entire website, but exclude everything in a folder called 'uploads' which exists in the root directory. I have googled for this, but didn't come up with anything, or I didn't think what I saw was right.

我们能破解这个?

推荐答案

试试这个 mod_rewrite的规则:

RewriteEngine on
RewriteRule !^uploads($|/) http://example.com%{REQUEST_URI} [L,R=301]

此规则不匹配任何URL路径,做的没有的开始,无论是 /上传 /上传/ (领先 / 在该模式由于路径preFIX去除.htaccess文件使用时丢失),并将请求重定向到相应的路径在 example.com 的。

This rule does match any URL path that does not begin with either /uploads or /uploads/ (leading / is missing in the pattern due to the path prefix removal when used in .htaccess files) and redirects the request to the corresponding path at example.com.

这篇关于重定向站点的.htaccess,但不包括一个文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆