Redirect Default CakePHP Pagination URL to SEO Friendly URL with .htaccess

In the previous post, I post a guide on how to create SEO friendly URL in CakePHP pagination.

However, if you already use default CakePHP pagination prior to that, you want to redirect the old pagination URL to the new SEO friendly URL.

I’m using .htaccess file to accomplish this.

Let’s take an example, by default we will have pagination URL like this

we would like to redirect to

To redirect, we have to edit .htaccess file located at /app/webroot/.htaccess. Next, add the following code.

RewriteEngine On
RewriteBase /
RewriteRule ^(.+)/page:([0-9]+)/$ /$1/page/$2/ [R=301,L]

Redirect Only Root Directory or Index Page with .htaccess

Previously, we looked at on how to Redirect Everything Except Root Page with .htaccess.

I have another domain where I need to redirect only root directory or index of the domain but not the sub-directory. You may need this is you have cPanel & you need to redirect the main domain without affecting your add-on domain.

To do this, I have to edit the .htaccess file in the root domain & add the following code. Remember to replace “yourolddomain” & “yournewdomain” with your domain name before using it.

RewriteEngine on
RewriteCond %{HTTP_HOST} yourolddomain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ [L,R=301]

Page 1 of 3123