.htaccess不排除规则的子目录



我在问一个有关我的.htaccess的问题。我会迅速解释我要完成的工作以及它是如何工作的。

我将$ _get目录作为页面的规则。

I.E https://example.com/test?p=page1 = https://example.com/test/page1
我还在此/test/Directory中有一个名为"帐户"的目录,但是当我尝试访问页面时。

https://example.com/test/account,它将我重定向到https://example.com/test/account/?p=account/?p = account
注意(https://example.com/test/account/正常工作)

我尝试通过在其他stackoverflow帖子上遵循方法来禁用它,但是这些都无法正常工作。

我的规则是:

RewriteRule ^([0-9a-zA-Z-_ ]+)/?$ index.php?p=$1 [NC,L]

有什么方法可以配置此规则以排除我尝试使用重写引擎的.htaccess的单词" account"one_answers" admin"等。是页面而不是目录。

我尝试了其他方法,以阻止目录具有相同的问题。它不认为/帐户是目录。它认为这是一个页面。

任何帮助都很好!

上面添加以上行以排除帐户或管理员的请求

RewriteCond %{REQUEST_URI} !(account|admin)$ [NC]

将其超过您当前的规则,它应在包括这些条款在内的请求中使用规则排除在外。

这是我使用的(有年龄),要做您想做的事:

**我很确定我可以将其简化为一组表达式,但我不太好。没有第二个,我错过了domain.tld,没有第一个我错过fancy.domain.tld

ErrorDocument 404 http://domain.tld
RewriteEngine On
RewriteCond %{REQUEST_URI} !(actionspage|/excludeddir/|/otherdir/).*$ [NC]
RewriteCond %{HTTP_HOST} ^(.+).domain.tld$ [NC]
RewriteRule ^(.*)$ index.php?pre=%1&pos=$1 [L,QSA]
RewriteCond %{REQUEST_URI} !(actionspage|/excludeddir/|/otherdir/).*$ [NC]
RewriteRule ^(.*)$ index.php?pre=0&pos=$1 [L,QSA]

最新更新