简体   繁体   中英

CakePHP URL rewriting not working on Ubuntu

I can't seem to get URL rewriting to work on a Ubuntu 12.04 server with apache2 and when the default page loads (home) it's just plain text without CSS . I'm using Cake 2.3.9 and I get the following message upon a fresh install to /var/www/. So my root directory looks like

/var/www/app
/var/www/lib
/var/www/index.php
/var/www/.htaccess
....

The error I get is

URL rewriting is not properly configured on your server. 1. Help me configure it 2. I don't / can't use URL rewriting

I tried everything in this post but I stil get the message.

The only thing from that post I didn't do is the accepted answer, which was

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.

Is that user suggesting to make sure .htaccess is /var/www? I don't quite get what they're suggesting to do. I downloaded Cake locally and then used SFTP to upload it to /var/www on my ubuntu server.

Unless there is some alternate modrewrite setting, I'm almost positive it's enabled. When I type sudo a2enmod rewrite it says Module rewrite already enabled

I've also tried everything here and still no luck. I'm completely stuck.

Yes, .htaccess will need to be in the public web root directory - /var/www in this case. Make sure the file is readable by your web server, too.

If this doesn't work: Make sure that the mod_rewrite module is installed and enabled. It should be on Ubuntu 12.04. You can check by listing the contents of /etc/apache2/mods-enabled. You should see rewrite.load listed.

If not, you can enable it as so:

sudo -i
cd /etc/apache2/mods-enabled
ln -s ../sites-available/rewrite.load rewrite.load
apache2ctl restart

I uninstalled and reinstalled my LAMP stack and it now works. I also downgraded to CakePHP 2.3.8 from 2.3.9, so maybe there was something in there too.

Regardless, it's now working!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM