cakephp doesn't work url-rewriting on Ubuntu

别来无恙 提交于 2019-12-05 18:22:49

问题


all. This time I try cakephp, but I have got "URL rewriting is not properly configured on your server. 1) Help me configure it 2) I don't / can't use URL rewriting". I could know this is apache and .htaccess issues such as /etc/apache2/sites-avaliable/default and each directory .htaccess.

My development environment...

  • Ubuntu12.04 on vmware fusion4
  • apache2.2.22
  • mysql5.5
  • php5.3.10
  • cakephp2.1

My process is followed...

1)/etc/apache2/httpd.conf

<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>

2)enabling mod_rewrite

sudo a2enmod rewrite
sudo service apache2 reload

3)editing /etc/apache2/sites-avaliable/default (AllOverride None to AllOverride All)

<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
Allow from all
</Directory>

prompt: sudo service apache2 reload

4)editing or checking each .htaccess file ->cake root directory

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$ app/webroot/    [L]
   RewriteRule    (.*) app/webroot/$1 [L]
   </IfModule>

->app root directory

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule    ^$    webroot/    [L]
   RewriteRule    (.*) webroot/$1    [L]
   </IfModule>

->webroot directory

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

This issue is solved, thank you.


回答1:


I had this problem as well. Turns out the .htaccess file was not getting copied alongside the cakePHP source. This is a common issue when using the cp command or not having hidden files visible in a file browser, unless you copy the top-level directory.

Doing a direct copy of the file to my project folder fixed it for me without having to mess with my apache settings.

cp ~/git/cakePHP/.htaccess ~/project/folder/



回答2:


Possible missconfiguration:

Check if File http://your_domain_name/css/cake.generic.css is rechable from your Browser. If not you will get the warning in the Default-Homepage

If you have a {HOME}/css Directory at the root level, UrlRewriting will not redirect http://your_domain_name/css/cake.generic.css to {HOME}/app/webroot/css/cake.generic.css.

Thus the css-File will not be found, causing the Message that URL-rewriting is not properly configured. (Look at File app/View/Pages/home.cpt)

Solution: Completly remove {HOME}/css Directory at root-level. Put your css-File at {HOME}/app/webroot/css.




回答3:


This could be a file permissions problem. Try recursively setting permissions to 777 for both the webroot and tmp directories. The tmp directory might require sudo.

sudo chmod -R 777 /path/to/app/webroot/
sudo chmod -R 777 /path/to/app/tmp/


来源:https://stackoverflow.com/questions/10835344/cakephp-doesnt-work-url-rewriting-on-ubuntu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!