Using overwrite for different folders

Currently, I have all my php files in 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 am currently planning to change it to rewrite query strings such as contact / test / yes, becomes contact.php? test = yes

My question is this: if I have an auxiliary folder that I need to rewrite (for example, root / subfolder1); how to rewrite the rule in this subfolder1 so that something like contact/test/yes not interpreted as a yes file that is inside the test folder inside the contacts folder?

Thanks for the previous help.

+4
source share
1 answer

you can either create each case or have a dynamic

Note: if the folder exists and you need to add this:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d 

if you create each case, you will need to specify each subfolder, for example:

 RewriteRule ^contact/test/([_a-zA-Z0-9]+)/?$ /contact.php?test=$1 [L,QSA] 

if this is dynamic for you, you will have to process each page in the main php file, and then create the logic in this file to analyze the correct information:

 RewriteRule ^([a-z0-9\-]+)/([a-z0-9\-]+)/([_a-zA-Z0-9]+)/?$ /index.php?page=$1&subpage=$2&lastpage=$3 [L,QSA] 
+17
source

All Articles