如果以上条件均不匹配,则Htaccess-rewriteRule



我有下面的htaccess,我正在尝试重写所有与任何规则都不匹配的url。

Options -Indexes
Options +FollowSymLinks
RewriteEngine On
# —————— rule1 ——————
RewriteCond %{REQUEST_URI} ^(.*)/learn/(why|about)$
RewriteRule ^(.*)/(.*)$ ./index.php?page=$2 [L,QSA]
# —————— rule2 ——————
RewriteCond %{REQUEST_URI} ^(.*)/profile/edit$
RewriteRule ^(.*)$ ./index.php?page=profile [L,QSA]
# —————— rule3 ——————
RewriteCond %{REQUEST_URI} ^(.*)/users/(.*)$
RewriteRule ^(.*)/(.*)$ ./index.php?page=user&userUrl=$2 [L,QSA]

我想要的是这种

RewriteCond %{REQUEST_URI} ^(.*)$
RewriteRule ^(.*)$ ./index.php?page=404 [L,QSA]

但它似乎不起作用。有什么办法做到这一点吗?谢谢

您的最后一条全包规则是这样的:

DirectoryIndex index.php
Options +FollowSymLinks -Indexes
RewriteEngine On
# —————— rule1 ——————
RewriteCond %{REQUEST_URI} ^(.*)/learn/(why|about)$
RewriteRule ^(.*)/(.*)$ index.php?page=$2 [L,QSA]
# —————— rule2 ——————
RewriteCond %{REQUEST_URI} ^(.*)/profile/edit$
RewriteRule ^(.*)$ index.php?page=profile [L,QSA]
# —————— rule3 ——————
RewriteCond %{REQUEST_URI} ^(.*)/users/(.*)$
RewriteRule ^(.*)/(.*)$ index.php?page=user&userUrl=$2 [L,QSA]
# —————— rule4 ——————
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php?page=404 [L,QSA]

最新更新