Friday, June 22, 2012

Re: mod_rewrite directive in http.conf

Yes I reloaded Apache, I actually rebooted the machine to be sure.

I did a bit of experimenting with various setups.

To eliminate anything I might have messed up I created a site from brand new CakePHP 2.1.3 install. The only changes I made were the standard things, change the Security.salt & Security.cipherSeed in core.php and permissions on the app/tmp/ folder to fix the errors mentioned on the default install home page.

I added a virtual host config for the site to apache...

<Directory "/path/to/serverdocs/cakephp2/app/webroot/">
Options All +MultiViews -ExecCGI -Indexes
AllowOverride None
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
</Directory>

I added the site to my hosts file

I then rebooted the machine.

I then visit my site on http://cakephp2 the default home page looks fine, the CSS is loading etc.

I then duplicated app/View/Pages/home.ctp calling it tester.ctp

When I visit http://cakephp2/pages/tester the page loads but the CSS doesn't and there is the message "URL rewriting is not properly configured on your server"

Changing the rewrite rule to the old style…

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

And restarting Apache makes my tester page work (CSS loads)

Setting allow override to All (rather than None) and restarting apache, my tester page works. Presumably I'm using the app/webroot/.htaccess whether I have the rewrite rule set to the new style or the old one

Then I looked at app/webroot/.htaccess and see that the rewrite rule is...

RewriteRule ^(.*)$ index.php [QSA,L]

Which is different to the RewriteRule ^(.*)$ index.php/$1 [QSA,L] that is mentioned in http://book.cakephp.org/2.0/en/installation/advanced-installation.html#apache-and-mod-rewrite-and-htaccess

Using this third option RewriteRule ^(.*)$ index.php [QSA,L] in my virtual host works fine with allow override on none…

<Directory "/path/to/serverdocs/cakephp2/app/webroot/">
Options All +MultiViews -ExecCGI -Indexes
AllowOverride None
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
</Directory>

Can you tell me what rewrite rule you have in your working config?

Paul


On 22 Jun 2012, at 01:31, lowpass wrote:

> Did you reload Apache? I do the same -- put the rewrite rules in a
> vhost.conf -- and it's working fine for me.
>
> Also, did you update index.php when you moved to 2.x?
>
> On Thu, Jun 21, 2012 at 6:13 AM, Paul Willis <paul.willis@me.com> wrote:
>> With CakePHP 1.x sites rather than use .htaccess files and associated performance hit on production machines I've always added a section to the apache virtual host config like this….
>>
>> <Directory "/path/to/serverdocs/mysiteroot/app/webroot/">
>> Options All +MultiViews -ExecCGI -Indexes
>> AllowOverride None
>> <IfModule mod_rewrite.c>
>> RewriteEngine On
>> RewriteCond %{REQUEST_FILENAME} !-d
>> RewriteCond %{REQUEST_FILENAME} !-f
>> RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
>> </IfModule>
>> </Directory>
>>
>> Which has always worked fine.
>>
>> Now I am switching to 2.x I read that the .htaccess file has changed, comparing old and new the only change I see is that the rewrite rule has changed from...
>>
>> RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
>>
>> to...
>>
>> RewriteRule ^(.*)$ index.php/$1 [QSA,L]
>>
>> …so I changed this in my virtual host config but it doesn't work - I get the classic mod_rewrite not working sign of a plain page with no CSS. The old 1.x way with index.php?url=$1 still seems to work fine with my 2.x site.
>>
>> So am I missing something here or should I stick with the old way?
>>
>> Paul
>>
>> --
>> Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
>> Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
>>
>>
>> To unsubscribe from this group, send email to
>> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php
>
> --
> Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
> Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.
>
>
> To unsubscribe from this group, send email to
> cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: