Using Rewrite for different folders
I currently have all my php files on the root folder, and I use this Rewrite Rule, which works fine:
ErrorDocument 404 /broken.php
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} ^/(index(\.(html|htm)))?$
RewriteRule %{REQUEST_URI} / [L,R,QSA]
RewriteCond %{REQUEST_URI} !^/(index(\.(html|htm)))?$
RewriteRule ^([_a-zA-Z0-9]+)/?$ /$1.php [L,QSA]
I currently plan to modify it so I can r开发者_如何学Cewrite query strings such as contact/test/yes becomes contact.php?test=yes
My question is this: if I have a sub folder that I need rewrite on (for example root/subfolder1); how do I rewrite the rule in this subfolder1 such that something like contact/test/yes
would not be interpreted as a yes file that's inside a test folder, which is inside a contact folder?
Thanks for all the previous help.
you can either create each case or having dynamic
note: if a folder exists and you need to add this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
if you create each case you will have to specify each sub folder like:
RewriteRule ^contact/test/([_a-zA-Z0-9]+)/?$ /contact.php?test=$1 [L,QSA]
if do you it dynamically you will have to process each page in a main php file then create a logic in that file to parse the correct info:
RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([_a-zA-Z0-9]+)/?$ /index.php?page=$1&subpage=$2&lastpage=$3 [L,QSA]
精彩评论