
Tom P
User

Dec 30, 2011, 10:59 AM
Post #5 of 5
(1532 views)
Shortcut
|
|
Re: [NigelGordijk] SEO friendly URLs
[In reply to]
|
Can't Post
|
|
Hello all, In my first response I missed an important character from the RewriteRule - the '$' at the end of the expression! In any case, here is a more detailed explanation of what to do... 1 - Check that mod_rewrite is loaded: create a php file with the following in it Upload it to your server and then look for 'mod_rewrite' (use f3 and type in 'mod_rewrite'). If it's not loaded, you'll need to get your server admin to enable it for you. 2 - At the start of your .htaccess file, make sure you have the following:
Options +FollowSymlinks Options +Indexes RewriteEngine On 3 - Make sure that you're using properly formatted expressions (for example, to redirect url from "/trails" to "/departments-development-details.php?Wilmot-Trails-4" you would use
RewriteRule ^trails$ /departments-development-details.php?Wilmot-Trails-4 or to point calls to "/Test-5" to "/index/parody.php?Test-5" use:
RewriteRule ^/([a-z]+)-([0-9]+)$ /index/parody.php?$1-$2 [NC] NOTE: Adding [NC] to the end of the RewriteRule makes the expression case insenstitive (No Case) The leading '^' and the trailing '$' anchor the expression you are looking for, in this case 'Trails' (so the string after the url contains only 'Trails' and nothing else) or 'Test-5' (the string after the url contains any number of letters followed by a dash followed by any number of digits - the actual letters and numbers are captured as variables in sequence ($1 and $2) and used to complete the redirect address - note that the '-' is still required as it is not captured as a variable). 4 - If you're getting 404 redirect errors, make sure that the page that you are redirecting to exists on the server (and that the page you are redirecting to has the leading '/'!) Getting .htaccess to do what you want is always tricky and I can only recommend reading, testing and the more reading to get comfortable with using .htaccess files. Another good resource for learning about .htaccess is http://www.easymodrewrite.com and the Apache docs at http://httpd.apache.org/docs/current/rewrite/. Hope this helps! Tom
|