且构网

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

htaccess的重定向任何要求

更新时间:2022-10-15 08:40:44

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

 选项+了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