如何修改整个网站,不包括几个子目录?

时间:2020-11-29 11:25:28

I've got a small problem. I've got a good setup which mod rewrites all requests to the site - the only thing is it also rewrites directories which I don't want to be included.

我有一个小问题。我有一个很好的设置,mod重写了对网站的所有请求 - 唯一的是它还重写了我不想包含的目录。

I'm using this code in my .htaccess file:

我在.htaccess文件中使用此代码:

RewriteEngine on
RewriteRule ^([^/\.]+)/?$ index.php?section=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?section=$1&page=$2 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?section=$1&page=$2&split=$3 [L]

Ideally I'd like to be able to exclude two directories - access/ and edit/ - edit/ also needs to have it's own set of rules:

理想情况下,我希望能够排除两个目录 - 访问/和编辑/ - 编辑/还需要拥有它自己的一套规则:

RewriteRule ^([^/\.]+)/?$ index.php?action=$1 [L]

I can get around this problem by linking directly to the .php file in either directory, but this isn't ideal.

我可以通过直接链接到任一目录中的.php文件来解决这个问题,但这并不理想。

Any advice?

2 个解决方案

#1


Use RewriteCond

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(access|edit)/
RewriteRule ^([^/\.]+)/?$ index.php?section=$1 [L]
...

(This is untested, but it should be close)

(这是未经测试的,但应该很接近)

#2


An alternate idea (also untested):

另一种想法(也未经测试):

RewriteEngine on
RewriteRule ^/access/ - [L]
RewriteRule ^/edit/([^/\.]+)/?$ /edit/index.php?action=$1 [L]
... (other rules)

which would save you from having to repeat the RewriteCond before every rule.

这样可以避免在每个规则之前重复RewriteCond。

#1


Use RewriteCond

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/(access|edit)/
RewriteRule ^([^/\.]+)/?$ index.php?section=$1 [L]
...

(This is untested, but it should be close)

(这是未经测试的,但应该很接近)

#2


An alternate idea (also untested):

另一种想法(也未经测试):

RewriteEngine on
RewriteRule ^/access/ - [L]
RewriteRule ^/edit/([^/\.]+)/?$ /edit/index.php?action=$1 [L]
... (other rules)

which would save you from having to repeat the RewriteCond before every rule.

这样可以避免在每个规则之前重复RewriteCond。