scarhand Posted June 18, 2008 Share Posted June 18, 2008 can anyone give me a site that would offer a good beginners guide for this? im talking about modifying the htaccess file or whatever....would like a little tutorial to get me started Quote Link to comment https://forums.phpfreaks.com/topic/110822-url-rewriting-for-seo/ Share on other sites More sharing options...
Daniel0 Posted June 19, 2008 Share Posted June 19, 2008 If you know regular expressions, then it's pretty trivial. First you start by enabling rewriting: RewriteEngine on Then to rewrite e.g. /profile/Daniel0 to index.php?act=profile&username=Daniel0 you can do this: RewriteRule ^/profile/([a-zA-Z0-9]+)$ index.php?act=profile&username=$1 See, it's separated by spaces. The second part is the regex, i.e. the URL from the user to match. In regular expressions, everything in parentheses are stored in backreferences. The third part is the URL to rewrite to and $1 will here be replaced by the username. After that you can optionally have some options (flags), such as redirection, stop looking for more entries, send a specific response code, etc. You can also set various conditions that should be met, e.g. that HTTPS must be on. You can read about it here and here. If you're starting from scratch, then this might be better: RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f # condition: only if the requested URL isn't a file that exists RewriteRule .* index.php # forward everything to index.php Then you can get the requested URL from $_SERVER['REQUEST_URI'] and then you can split it up or you can use regex there to send the request data to whatever place that should take care of that specific request. Quote Link to comment https://forums.phpfreaks.com/topic/110822-url-rewriting-for-seo/#findComment-568814 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.