Hello everyone,

I was looking for way to change the URL using the prettyURL without changing the file name. As you may know, if you change the file name Couch see this file as a new template.

Here is the way I found to do it, first you need to change the .htaccess, what I do was: make a copy of the rule from the template I want to change and in the copy change the URL, like this:

from:
Code: Select all
#blog.php
RewriteRule ^blog$ "$0/" [R=301,L,QSA]
RewriteRule ^blog/$ blog.php [L,QSA]
RewriteRule ^blog/.*?([^\.\/]*)\.html$ blog.php?pname=$1 [L,QSA]
RewriteRule ^blog/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ blog.php?d=$1$2$3 [L,QSA]
RewriteRule ^blog/[^\.]*?([^/\.]*)/$ blog.php?fname=$1 [L,QSA]
RewriteRule ^blog/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]


to:
Code: Select all
#blog.php
RewriteRule ^blog$ "$0/" [R=301,L,QSA]
RewriteRule ^blog/$ blog.php [L,QSA]
RewriteRule ^blog/.*?([^\.\/]*)\.html$ blog.php?pname=$1 [L,QSA]
RewriteRule ^blog/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ blog.php?d=$1$2$3 [L,QSA]
RewriteRule ^blog/[^\.]*?([^/\.]*)/$ blog.php?fname=$1 [L,QSA]
RewriteRule ^blog/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]

#blog.php
RewriteRule ^blog-with-new-url$ "$0/" [R=301,L,QSA]
RewriteRule ^blog-with-new-url/$ blog.php [L,QSA]
RewriteRule ^blog-with-new-url/.*?([^\.\/]*)\.html$ blog.php?pname=$1 [L,QSA]
RewriteRule ^blog-with-new-url/([1-2]\d{3})/(?:(0[1-9]|1[0-2])/(?:(0[1-9]|1[0-9]|2[0-9]|3[0-1])/)?)?$ blog.php?d=$1$2$3 [L,QSA]
RewriteRule ^blog-with-new-url/[^\.]*?([^/\.]*)/$ blog.php?fname=$1 [L,QSA]
RewriteRule ^blog-with-new-url/[^\.]*?([^/\.]*)$ "$0/" [R=301,L,QSA]


Now you need to make some changes in Couch (v.1.4.7), in functions.php line 1168 you can place this code:

Code: Select all
function get_pretty_template_link( $template_name ){
              switch($template_name)
                  {
                       case 'blog.php';
                           return 'blog-with-new-url/';
                              break;
                       default;
                           return $this->get_pretty_template_link_ex( $template_name, $dummy );
                              break;
                  } 
        }

Done! Now you have a new URL without losing all your data.

ps1: You don't need to keep the 'old' rule in .htaccess
ps2: I think you can change the file name and change the database too, but I'm not sure.