How to change below rewrite url to allow more sub folder, when all url redirected to index page?

ぃ、小莉子 提交于 2019-12-24 12:43:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!