简体   繁体   English

CakePHP URL重写在Ubuntu上不起作用

[英]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 . 我似乎无法使URL重写在具有apache2的Ubuntu 12.04服务器上正常工作,并且当默认页面加载(主页)时,它只是纯文本而没有CSS。 I'm using Cake 2.3.9 and I get the following message upon a fresh install to /var/www/. 我正在使用Cake 2.3.9,并且在重新安装到/ 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. 您的服务器上没有正确配置URL重写。 1. Help me configure it 2. I don't / can't use URL rewriting 1.帮助我配置它2.我不/不能使用URL重写

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. 事实证明.htaccess文件未与cakePHP源一起复制。 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. 当使用cp命令或在文件浏览器中看不到隐藏文件时,这是一个常见问题,除非您复制顶层目录。 Doing a direct copy of the file to my project folder fixed it for me without having to mess with my apache settings. 将文件直接复制到我的项目文件夹中对我来说是固定的,而不必弄乱我的Apache设置。

Is that user suggesting to make sure .htaccess is /var/www? 该用户是否建议确保.htaccess为/ 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. 我在本地下载Cake,然后使用SFTP将其上传到ubuntu服务器上的/ var / www。

Unless there is some alternate modrewrite setting, I'm almost positive it's enabled. 除非有一些其他的modrewrite设置,否则我几乎肯定它已启用。 When I type sudo a2enmod rewrite it says Module rewrite already enabled 当我输入sudo a2enmod rewrite它说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. 是的,在这种情况下,.htaccess将需要位于公共Web根目录-/ var / www中。 Make sure the file is readable by your web server, too. 确保文件也可被您的Web服务器读取。

If this doesn't work: Make sure that the mod_rewrite module is installed and enabled. 如果这不起作用:确保已安装并启用了mod_rewrite模块。 It should be on Ubuntu 12.04. 它应该在Ubuntu 12.04上。 You can check by listing the contents of /etc/apache2/mods-enabled. 您可以通过列出/ etc / apache2 / mods-enabled的内容进行检查。 You should see rewrite.load listed. 您应该看到列出了rewrite.load。

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. 我卸载并重新安装了LAMP堆栈,现在可以使用了。 I also downgraded to CakePHP 2.3.8 from 2.3.9, so maybe there was something in there too. 我也从2.3.9降级到CakePHP 2.3.8,所以也许里面也有东西。

Regardless, it's now working! 无论如何,它现在正在工作!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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