在我的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。
例如,有人输入了网址www.test.com/client/data/private/test.jpg
,服务器应该将请求作为index.php?request1=client/data/private/test.jpg
。index.php?request2=$1
我无法按照预期获得第2点功能。
我使用以下.htaccess文件来处理:
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]
我在这里做错了什么?
答案 0 :(得分:2)
试试这段代码:
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]