CakePHP: URL Rewriting

What is Mod_Rewrite?

Simply put, mod_rewrite is an Apache module that let’s you rewrite urls based on rules you define.

Some other common uses for mod_rewrite: 
  • Directing all traffic from multiple domain names to one domain
  • Directing all traffic from www and non-www to one location
  • Blocking traffic from specific websites
  • Blocking spammy searchbots and offline browsers from spidering your site and eating your bandwidth
  • Mask file extensions
  • Preventing image hotlinking (other web pages linking to images on your server)

Cake PHP URLs can be made SEO friendly by using the overwrite rule and modifying the htacess file of the root folder as shown below:

The below example of URL Rewrites for the site has n level menus, 

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^([^/]+html)$ app/webroot/controller_name/function_name/$1 [L]
   RewriteRule ^[^/]+/([^/]+html)$ app/webroot/controller_name/function_name/$1 [L]
   RewriteRule ^[^/]+/[^/]+/([^/]+html)$ app/webroot/controller_name/function_name/$1 [L]
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
Running URL Rewrite sucessfully, we need to enable the in the httd.conf of Apache Server.
 LoadModule rewrite_module modules/



  1. March 18, 2009 at 12:59 pm

    […] Šiek tiek SEO, “pagražinant” nuorodas su mod_rewrite 2009.03.18 Developing’as cache, CakePHP, jquery, […]

    • rafeekphp said,

      March 19, 2009 at 12:51 pm

      Thanks 🙂 adding my blog on your site.

  2. Jipson said,

    May 13, 2010 at 12:12 pm


    I have a cakephp site like, where admins_controller is my controller name. How I can access the same by

    Thanks and Regards,

    • rafeekphp said,

      July 9, 2010 at 6:22 am


      In your route.php you have to mention controller,view and action name in order to access the admin login section.
      We have already default route for client section with that you have to add new route to point the admin also.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: