Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Double content

Hi there!

I wonder how to avoid the double content of my Phalcon projects when in path '/' and '/public/' there is the same content.

It's kinda bad for SEO, so I wonder.

Thanks in advance!


Hey friend, I was having the same problem. Tried my best to make it work with htaccess, but failed miserably, since I'm not htaccess expert.

This is my old htaccess post and David's suggestion.

For now I've made a PHP solution in my "bootstrap" file, until I find a better one. It's working, so if you fail with htaccess too, you can use it :)

Sample url for our test: http://localhost/framework-v1.0/public/api/v1/documentation/news

$redirect = false;

// 301 Redirect if /public/index.php (this only shows homepage so just redirect to real homepage)
$currentUrl = getCurrentUrl(); // My custom function which returns: http://localhost/framework-v1.0/public/api/v1/documentation/news
$currentPath = str_replace($config->site->url, '', $currentUrl); // Result: api/v1/documentation/news
if (strpos($currentUrl, 'public/index.php') !== false) {
    $redirect = $config->site->url; // In my case $config->site->url is http://localhost/framework-v1.0/

// 301 Redirect if /public/ - Replace only the first occurance of /public/ (Redirect to same url but without the first /public/ in it)
if (substr($currentPath, 0, 6) == 'public') {
    $needle = '/public/';
    $redirect = substr_replace($currentUrl, '/', strpos($currentUrl, $needle), strlen($needle));
    // Result with correct url: http://localhost/framework-v1.0/api/v1/documentation/news

if ($redirect) {
    return $di->getResponse()->redirect($redirect, true, 301)->send();

PS1: I think you can do something with the server configuration, but since in most cases I don't have access to the server I can't afford to go this path.

PS2: If you find a better solution please update the post to help others.

edited Nov '16

The most convenient and recommended soultion is to set your webserver root to target directly your /public directory. That way, you'll have only one route. With nginx: root /path/to/your/web/folder/yourapplication/public

edited Nov '16

Thanks @nikolaymihaylov for your feedback, your answer is quite good, unfortunatly I'm not a regex pro, so I have some troubles with this.

@stamster your way of solving this problem is for me the best choice

Best luck to you!