I use the below mod rewrite code for urls like: www.site.com/play/543
RewriteEngine On
RewriteRule ^play/([^/]*)$ /index.php?play=$1 [L]
How can I expand on this so I can have a couple urls like www.site.com/contact
and www.site.com/about
I use the below mod rewrite code for urls like: www.site.com/play/543
RewriteEngine On
RewriteRule ^play/([^/]*)$ /index.php?play=$1 [L]
How can I expand on this so I can have a couple urls like www.site.com/contact
and www.site.com/about
RewriteRule ^(play|contact|about)/([^/]*)$ /index.php?$1=$2 [L]
Might do the trick. Now requests to /play/foo points to /index.php?play=foo and /contact/bar points to /index.php?contact=bar and so on.
Edit, from comment "about and contact will never be set though."
Just use two rewrites then;
RewriteRule ^play/([^/]*)$ /index.php?play=$1 [L]
RewriteRule ^(contact|about)/?$ /index.php?a_variable_for_your_page=$1 [L]
The common way used by most of the PHP frameworks is just passing whatever the user requests except existing files (generally assets *.png, *.js *.css) and/or public directories to a PHP script and then interpreting the route on the PHP side.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d #if not an existing directory
RewriteCond %{REQUEST_FILENAME} !-f #if not an existing file
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L] #pass query string to index.php as $_GET['url']
</IfModule>
On the PHP side it is very important to avoid things like this
$page = getPageFromUrl($_GET['url']);
include($page);
So be very careful when taking the user input and sanitize/filter to avoid the remote user to access non-public files on your web host.