Try this code:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule "^([^/]+)/([^/]+)/([^/]+)(/.*)?$" /$1$4?$2=$3 [L,QSA]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [QSA,L]
Question
I'm trying to create a regexp for my .htaccess with high amount of flexibility, I know my solution is not the best, but this is what I want for the specific project.
So.
/website is my base and .htaccess currently look like:
RewriteRule ^([A-Za-z0-9-]+)/$ index.php?page=$1&$2 [NC,L]
This works fine aslong as I am visiting /website/anypagename pages. What I want to do next is ?to=allow&getquery=strings and fetch them with $_GET in php, but the .htaccess won't let me.
I also want my .htaccess to allow ANY /-urls where the structure would look like:
/website/pagename/z1/x1/z2/x2/z3/x3
where z1 is a name of a $_GET
variable, and x1 is its value. Of course normal get arguments shall work aswell.
However I tweak it I can't get it to do what I want. Also, with the z1/x1 structure - will I be able to visit physical files or even load css?
Solution
Try this code:
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteRule "^([^/]+)/([^/]+)/([^/]+)(/.*)?$" /$1$4?$2=$3 [L,QSA]
RewriteRule ^([^/]+)/?$ /index.php?page=$1 [QSA,L]