php - How do I set up mod rewrite to do this? -
hi guys heres scene - i'm building web application creates accounts users. setup file structure:
root/index.php root/someotherfile.php root/images/image-sub-folder/image.jpg root/js/somejs.js when users create account choose fixed group name , users can join group. thought of having textbox in login screen enter group user belongs login to. instead have virtual folders in case:
root/group-name/index.php i heard can done apache mod rewrite i'm not sure how - here?
basically instead of having &group-name=yourgroupname appended every page of nature above.
you can configure mod rewrite in .htaccess file, e.g.
root/.htaccess:
rewriteengine on #make sure urls represent files or directories not rewritten rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d #update if files not in /root rewritebase /root rewriterule ^([^/]+)/(.*\.php)$ $2?group-name=$1 [l,qsa] so request matching /[groupname]/[php file] should re-written /[php file]?group-name=[groupname].
lmeans last rule, if matches don't continue running other rulesqsameans append original query string (so other parameters still passed php script)
you maybe replace pattern matches groupname ([^/]+) more restrictive, e.g. ([a-za-z0-9_-]+).
you can put configuration in 1 of apache configuration files, can faster parsing .htaccess file on every request.
Comments
Post a Comment