SEO friendly URLs

5 posts by 3 authors in: Forums > CMS Builder
Last Post: December 30, 2011   (RSS)

By 1980 - December 26, 2011

Hi,

aren't there any rewrite settings in CMS Builder?

at the moment my details pages look like

eg
/index.php?Test-5

would like to have /Test-5.php or /Test-5/

Thanks

Re: [1980] SEO friendly URLs

By (Deleted User) - December 27, 2011 - edited: December 27, 2011

Hi 1980,

CMSB doesn't have a built in .htaccess editor so you'll have to create your own .htacces file and add the rewrite rules yourself.

To do so, create a plain text file and save it with the extension ".htaccess" (but no file name).

Edit that file and add the following (to change URL from "/Test-5" to "/index.php?Test-5" )

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/([a-z]+)-([0-9]+) http://yourdomain.com/index.php?$1-$2 [NC]


This will allow you to use links in your code of the form "http://yourdomain.com/Test-5" and have the browser show the page as if it were viewing "http://yourdomain.com/index.php?Test-5".

There are a lot of things that .htaccess can do - a good resource for htaccess rules is http://www.htaccess-guide.com/.

Hope this helps,

Tom

Re: [Tom P] SEO friendly URLs

By 1980 - December 29, 2011 - edited: December 29, 2011

thanks for the help Tom

the actual file is called parody.php in a directory called 'index', so I tried the variations on following code

RewriteRule ^/index/parody.php?([a-z]+)-([0-9]+) http://www.mysite.com/index/parody.php?$1-$2 [NC]

[font "Verdana"]but that gives a 404 error (had a look on your link, but couldn't find more info on these rewrites)

Re: [NigelGordijk] SEO friendly URLs

By (Deleted User) - December 30, 2011

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
<?php phpinfo(); ?>
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 httpd.apache.org/docs/current/rewrite/.

Hope this helps!

Tom