htaccess的URL重写帮助重写、htaccess、URL

2023-09-02 01:14:09 作者:难得爱浓

我有以下重写网址:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs 
RewriteRule ^(.*)$ index.php?page=$1 [PT,L]

现在我想添加一个例外,即如果URL是这样mysite.com/abc应该忽略它,并在它里面所有的东西也。 mysite.com/abc/dfgs也应排除这个重写。

Now I want to add an exception, that if the URL is something like mysite.com/abc it should ignore it and all things inside it also. mysite.com/abc/dfgs also should be excluded from this rewriting.

我怎样才能做到这一点?

How can I accomplish this?

推荐答案

如果/ ABC是现有的目录,你可以把在那里的另一个.htaccess文件以

If /abc is an existing directory, you can put another .htaccess file in there with

RewriteEngine Off

如果这是真的,你要不能重写(它是否存在与否)只是一个字符串

If it's really just one string you want to not rewrite (whether it exists or not)

RewriteCond %{REQUEST_URI} !^/abc

如果请求的路径以/ ABC

will not rewrite if the requested path starts with "/abc"

要测试重写规则没有搞乱的网站经常浏览器(不是说你应该在编辑过程中的现场环境,这纯粹是假设的:-)),我发现以下非常有帮助的:

To test rewrite rules without messing up the site for regular browsers (not that you should be editing in a live environment of course, this is purely hypothetical :-) ), I've found the following very helpful:

RewriteCond %{REMOTE_ADDR} 12.34.56.78 # <-- where that's your IP address