Documentation > Core Concepts > Pretty URLS

Pretty URLS

Couch supports the use of Pretty URLS (aka search engine friendly - SEF URLs).
This feature uses URL rewriting to transform the default Couch URLs containing querystrings into URLs that appear more friendly and relevant to the web pages.
For Example, a URL like this -

http://www.mysite.com/blog.php?f=3

where 3 is the id of a folder named 'electronics', will get converted to -

http://www.mysite.com/blog/electronics/

and another URL -

http://www.mysite.com/blog.php?p=12

where 12 is the id of a cloned page named 'mobile-phones' which is in 'electronics' folder, will get converted to -

http://www.mysite.com/blog/electronics/mobile-phones.html

It is obvious that the 'pretty' versions of the URLs convey more meaning about the pages they represent.
Not only do they appear friendlier to the visitors but they also offer immense benefit from the SEO (Search Engine Optimization) perspective - something that cannot be ignored if you wish your pages to rank high in Google search.

For Pretty URLS to work in Couch, the Apache server it is hosted on must have the 'mod_rewrite' module enabled.

 

ENABLING PRETTY URLS

In Couch Pretty URLS apply only to clonable templates.
By default, Pretty URLS are not enabled. It is strongly advised that you turn this feature on only after you have configured all your clonable templates.

Enabling Pretty URLS is a two step process -

1. Find and modify the following line in config.php -

// 8.
// Set the following to '1' if you wish to enable Pretty URLS.
// After enabling it, use gen_htaccess.php to generate an .htaccess file and place it in the root folder of your site.
define( 'K_PRETTY_URLS', 0);

Set the K_PRETTY_URLS to 1.

2. Fire up your browser and visit the following page (substitute the domain name with that of yours)-
http://www.yoursite.com/couch/gen_htaccess.php

A list of rewrite rules should appear on the page.
Select and copy the ENTIRE content of the page (press Ctrl + A) and paste it into a file named '.htccess' and place this file in your website's root.

If you are on a Windows machine, your OS might not allow you to create a file which only has an extension and no name. For such cases name the file temporarily to anything e.g. 'dummy.htaccess', upload it to your server and then rename it to remove the name.

Try visiting your cloned pages from the Admin Panel and the pretty urls should be now seen in action.

The rules that are copied and pasted into the .htaccess file pertain to all your clonable templates. If you happen to add other clonable templates after you have taken the steps outlined above, you'll have to regenerate the rewrite rules (using gen_htaccess.php) and replace the former contents of the .htaccess file with these new rules.
This is the reason why it is advisable to turn on Pretty URLS after all the clonable templates are already in place.