Regex 重写条件不起作用
在我的Regex 重写条件不起作用,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,在我的php-项目中,我有以下文件夹结构 / [root] |-- ... [some other folders] |-- util/ // containing js,css files; should be accessible for anyone. |-- client/ |--data/ // contains files which can be uploaded by users |-- privat
php
-项目中,我有以下文件夹结构
/ [root]
|-- ... [some other folders]
|-- util/ // containing js,css files; should be accessible for anyone.
|-- client/
|--data/ // contains files which can be uploaded by users
|-- private/ // should only be accessible for logged in users
|-- public/ // should be accessible for anyone.
|-- ... [some other folders]
|-- index.php
我希望实现以下行为:
client/
中的任何文件,应该将其重定向到index.php。
例如,有人输入urlwww.test.com/client/data/private/test.jpg
服务器应以index.php?request1=client/data/private/test.jpg
的形式获取请求index.php?request2=$1
RewriteEngine On
# allow access to all files within util/ WORKS!!
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)(util)($|/) - [L]
# here i have problems.. how can i achieve, that access to folder client/ is rewritten to index.php?request1=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^client
RewriteRule ^(.*)$ index.php?request1=$1 [QSA,L]
# rewriting everything else WORKS!!
RewriteRule ^(.+)$ index.php?request2=$1 [QSA,L]
我做错了什么 请尝试以下代码:
RewriteEngine On
# allow access to all files within util/ WORKS!!
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^util($|/) - [L]
# here i have problems.. how can i achieve, that access to folder client/ is rewritten to index.php?request1=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^client(/.*|)$ index.php?request1=$1 [QSA,L]
# rewriting everything else WORKS!!
RewriteRule ^((?!index\.php).+)$ index.php?request2=$1 [QSA,L]
如果未请求特定文件,则
/client/dir1/dir2
会发生什么情况?是应该重写为index.php,还是应该不修改目录访问?这应该被重写规则3捕获,或者抛出以下http错误401404之一。但是我更喜欢规则3Ah等等--请求URI
在匹配为^/client
时可能应该有一个前导的//code>,因为这是头的结构。这与RewriteRule
在目录上下文中所期望的匹配方式相反。试一试,这可能就是你所需要的。其他一切对我来说都很好。那也不起作用。。。但我想,感谢您重新编写日志并开始调试。RewriteRule:无法编译正则表达式“^((?!index\\.php.+)$”