Reputation: 659
In my php
-project, I have the following folder structure.
/ [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
I want to achieve the following behaviour:
client/
it should be redirected to index.php.
For example someone enters the url www.test.com/client/data/private/test.jpg
the server should get the request as index.php?request1=client/data/private/test.jpg
.index.php?request2=$1
I am not able to get point 2 function as per the expectation.
I use the following .htaccess file, to handle this:
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]
What am i doing wrong here?
Upvotes: 3
Views: 975
Reputation: 785128
Try this code:
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]
Upvotes: 2