CakePHP HTML helper CSS tag and Apache Alias

As a relative newcomer to CakePHP, I'm hoping for some advice on the "right" way of configuring Apache and CakePHP to find included files (CSS, JavaScript, etc).

If my server's DocumentRoot is set to /var/www and I install and configure CakePHP in /var/www/somepath/cakeapp I can access the application as expected at the URL

However, if I use the HTML helper to generate the CSS link tag in my default layout, I start to run into trouble. For example, the code

echo $html->css('styles');

produces this tag:

<link rel="stylesheet" type="text/css" href="/somepath/cakeapp/css/styles.css" />

However, the CSS actually lives in /somepath/cakeapp/app/webroot/css.

If the CakePHP app were the only thing on my domain, I could point the DocumentRoot at /var/www/somepath/cakeapp/app/webroot as the documentation suggests and all would (presumably) be well. However, that's not an option for me.

Is there a generally accepted correct way of configuring Apache and CakePHP so that the HTML helper can produce the correct link tag?

Edit: I feel there must be some combination of CakePHP configuration and Apache Aliases that I haven't run across yet.


/somepath/cakeapp/css/styles.css is actually the correct path that needs to be displayed in the links.

The reason why it gets displayed as such is because of the .htaccess file in your cakeapp directory that redirects (rewrites) requests to the cakeapp/app/webroot directory.

Now, the reason why this structure even exists is because generally, you have "public" and "non-public" parts in your application. The "non-public" parts contain the PHP code including controllers, models, views, plugins, cake library, etc. The "public" parts include the css, scripts, and image files.

Now, you could make your /var/www/html folder as your app directory to make it secure. In order to completely configure your application to your liking, check the cakeapp/app/bootstrap.php file and change the relevant settings. You can learn more about that here.

In short, no worries. The path you see is right!

Try defining RewriteBase in your .htaccess files in Cake's root directory, /app and /app/webroot to point to your subdirectory. Set them to the respective paths, /somepath/, /somepath/app/ and /somepath/app/webroot/

Need Your Help

What does sun.awt.geom.Crossings do?

java awt

I've been away from Java for several years, so forgive my rust. I inherited some code targeting Java SE 1.5. When building under Java 1.7.0, there are several build warnings with the text:

list iterator + operator

c++ stdlist

// ((++currentEntry)--) is equivalent to (currentEntry + 1). Kind of.

Asking for user input in long running operation

android multithreading android-asynctask

I have an application where a user can backup/restore his files to/from a server.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.