问题
I am trying to change the below rewrite rule to accept more folders. Currently any other url else mydomain.com\test
will be directed to index.php
.
RewriteRule ^((?!test).)*$ index.php [QSA,L]
I need to add more subfolders like test1
, test2
etc. So that I can access url \test1
, \test2
etc.
Rewrite Rule
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!test).)*$ index.php [QSA,L]
回答1:
Well...
What you have already also matches /test1
and /test2
because the regex you have only checks that something doesn't start with /test
, and both /test1
and /test2
starts with /test
.
But if you want it to check multiple folders that don't all start with the same thing, then use the |
in the expression. Say you also want to exclude /blah
and /bleh
:
RewriteRule ^((?!test|blah|bleh).)*$ index.php [QSA,L]
回答2:
one of many ways:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/test/
RewriteCond %{REQUEST_URI} !^/test1/
RewriteCond %{REQUEST_URI} !^/test2/
RewriteRule ^(.*)$ index.php [QSA,L]
来源:https://stackoverflow.com/questions/14303192/how-to-change-below-rewrite-url-to-allow-more-sub-folder-when-all-url-redirecte