htaccess的重定向任何要求 [英] htaccess to redirect ANY request

查看:164
本文介绍了htaccess的重定向任何要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两部分......

第1部分 - 我想重定向任何请求到不存在的目录... 到它的新位置... AND和文件不存在 - 它是新的位置

这样:myDomain.com/myFolder(不再存在) 被重定向到myDomain.com/newLocation/myFolder

和/或

myDomain.com/myFolder.htm(不存在) 被重定向到myDomain.com/newlocation/myFolder

这是靠近...

  RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^ MyFolder中http://myDomain.com/newLocation/myFolder
 

不过,我并不一定要输入每个有问题的文件夹名称,我倒是preFER有请求失败前的'newLocation目录检查......对任何请求,而不仅仅是事情,我明确名称

第2部 有人可以解释在htaccess的使用的符号 - 或点我到一个列表... 例如:

 的RewriteCond%{REQUEST_URI} ^ / $重写规则^(。*)$%{REQUEST_URI} /
 

我看那个,我知道有含义T0 ^ / $等 - 正则表达式嫌(不熟悉)  或本

 的RewriteCond%{} REQUEST_FILENAME!-f(什么!-f意思????)
的RewriteCond%{} REQUEST_FILENAME!-d(什么!-d意思????)
重写规则(。*)的index.php?_var = $ 1 [L](在$ 1表示......)
 

我想了解的符号和语法...

解决方案

对于第一部分在这里是规则将需要:

 选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
#如果请求的URI不是一个文件,而不是一个目录
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
#外部重定向到/ newLocation / {URI}
重写规则^ / newLocation%{REQUEST_URI} [L,R = 301]
 

要回答第2部分这里是 URL重写官方文档

two parts....

PART 1 - I want to redirect any request to a directory that DOES NOT exist... to a it's new location... AND and file that does not exist - to it's new location.

so: myDomain.com/myFolder (which no longer exists) gets redirected to myDomain.com/newLocation/myFolder

and / or

myDomain.com/myFolder.htm (which does NOT exist) gets redirected to myDomain.com/newlocation/myFolder

this is close...

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^myFolder http://myDomain.com/newLocation/myFolder 

But I don't necessarily want to TYPE every questionable folder name, I'd prefer to have the 'newLocation" directory checked before the request fails...on any request, not just things i explicitly name

PART 2 Can someone explain the symbols used in the htaccess - or point me to a list... example:

RewriteCond %{REQUEST_URI} ^/$ Rewriterule ^(.*)$ %{REQUEST_URI}/

I look at that and I know there are meanings t0 ^/$ etc - smacks of RegEx (not familiar) or this

RewriteCond %{REQUEST_FILENAME} !-f (what's the !-f mean ????)
RewriteCond %{REQUEST_FILENAME} !-d (what's the !-d mean ????)
RewriteRule (.*) index.php?_var=$1 [L] ( the $1 means ...) 

I want to understand the symbols and the syntax...

解决方案

For Part 1 here is the rule will need:

Options +FollowSymLinks -MultiViews
RewriteEngine on
# if requested URI is not a file and not a directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# externally redirect to /newLocation/{URI}
RewriteRule ^ /newLocation%{REQUEST_URI} [L,R=301]

For answer to part 2 here is the Apache mod_rewrite official documentation

这篇关于htaccess的重定向任何要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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