如何在WampServer中配置CakePHP的.htaccess文件?

发布于 2024-10-06 17:09:19 字数 2751 浏览 0 评论 0原文

我对在 CakePHP 中运行示例必须做什么感到非常困惑...

我正在使用 WAMP 服务器,它位于“C:/program files/wamp/”中,我为我的项目使用另一个分区:“ E:/项目/”。

有一个用于学习 CakePHP 的文件夹:“E:/Projects/cakephp/”。我已将所有 CakePHP 提取的内容放入该文件夹中(包含:index.php、.htaccess、readme.txt 和文件夹:app、cake、插件、供应商)...

首先,我在 Apache 中设置一个指向“E:/Projects/cakephp/”的别名 (test),但它不起作用(消息:哎呀!此链接似乎已损坏。

经过一番搜索,我发现我必须将别名设置为另一个文件夹:“E:/Projects/cakephp/app/webroot/”,并且它工作得很好,并向我展示了 CakePHP 框架的第一页。

我解决了第一页中的所有问题(使用 CakePHP 手册)。我尝试遵循 CakePHP 博客教程...我制作了一个模型、一个控制器和一个视图页面(所有这些都与“帖子”主题相关),但是当我尝试查看结果时,我刚刚收到了 WAMP 服务器的第一页(显示地址中有一些问题)

我使用的地址:“http://localhost/test/ posts/index”(这不起作用) 然后,我尝试将index.php放在url中:“http://localhost /test/index.php/posts/index”并且成功了!

.htaccess 文件,当我尝试到达根目录“http://localhost/test/“工作完美,我不知道出了什么问题!

xx 我在 StackOverflow 中发现了同样的问题,这里。它的所有设置都与我的类似,只是他似乎将别名设置为 CakePHP 的根目录,但它对我不起作用!

实际上我找不到如何使用该解决方案(链接)这对他有帮助,因为我认为我的情况有点不同!

我的以下 cakephp 文件夹的 htaccess 文件如下,

cakephp 的根

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

/app

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

/app/webroot

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

我希望有人可以帮助我,我我真的很累...

提前感谢您的时间和解决方案!

--------------------------------------------------------- --------------------------------

哟哟哟!我找到了答案!我对所有 htaccess 文件进行了许多更改!如果您也遇到此问题,请首先删除所有更改,然后使用此 链接有很大帮助! 希望对你也有帮助!芝士们!很多芝士!! :D

I'm absolutely confused about what I must do to run my sample in CakePHP...

I'm using WAMP Server and it is located in "C:/program files/wamp/" and I use another partition for my projects: "E:/Projects/".

there is a folder for Learning CakePHP: "E:/Projects/cakephp/". I've put all the CakePHP extracted contents in that folder (consist of: index.php, .htaccess, readme.txt and folders: app, cake, plugins, vendors)...

First, I set an alias name (test) in Apache that pointed to "E:/Projects/cakephp/", and it didn't work (message: Oops! This link appears to be broken.)

After some search, I found that I must set the alias to another folder: "E:/Projects/cakephp/app/webroot/", and it worked perfectly and showed me the first page of CakePHP Framework.

I solved all the issues in the first page (using the CakePHP manual). I tried to follow CakePHP blog tutorial ... I made a model, a controler and a view page (all related to "posts" subject), but when I try to see the result I just received the first page of WAMP server (showing that there is some problem in the address)

I used the address: "http://localhost/test/posts/index" (that didn't work)
then, I tried to put index.php in the url: "http://localhost/test/index.php/posts/index" and it worked!

.htaccess files when I try to reach the root "http://localhost/test/" work perfect, I don't know what's wrong!

xx I found the same question in StackOverflow, here . All of its settings is similar to mine except it seems he set the alias to the root of CakePHP, and it didn't work for me!

and actually I couldn't find how I can use the solution (link) that helped him, because I think it is a little different in my case!

My htaccess files for following cakephp folders are as following,

root of the cakephp

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

/app

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

/app/webroot

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

I hope someone can help me, I'm really exhausted...

thanks in advance for your time and your solutions!

-------------------------------------------------------------------------------

Yoohoooo! I found the answer! I had made many changes in all of my htaccess files! If you have this problem too, first remove all of your changes and then use this link as a great help!
Hope it help you too! CHEEEEERS! MANY CHEEEEERS!! :D

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

﹏半生如梦愿梦如真 2024-10-13 17:09:19
  1. 右键单击您的 WAMP 图标
    任务栏
  2. 然后将鼠标悬停在 Apache 模块上向下
  3. 滚动并确保勾选了 rewrite_module
  1. Right click on the WAMP icon on your
    task bar
  2. Then Hover over Apache Modules
  3. Scroll down and make sure rewrite_module is ticked
深海少女心 2024-10-13 17:09:19

其实我也遇到了和你一样的问题,但是不记得怎么解决的了。

我可以向您保证这不是 .htaccess 问题,而是 Apache 的配置错误。

认为我修改的部分就是这个。

<Directory />
    #Options +Indexes
    Options FollowSymLinks
    AllowOverride All
    #Order deny,allow
    #Deny from all
</Directory>

请注意我如何评论某些行。虽然我无法确认这一点,因为我没有默认的配置文件。

I actually got the same issue as you, but I don't remember how I solved it.

What I can assure you it's not a .htaccess issue, but a configuration error of Apache.

I think the part I modified was this one.

<Directory />
    #Options +Indexes
    Options FollowSymLinks
    AllowOverride All
    #Order deny,allow
    #Deny from all
</Directory>

Note how I commented some lines. Altough I can't confirm this, since I don't have the default configuration file.

揪着可爱 2024-10-13 17:09:19

我遇到了同样的问题,这是对我有用的解决方案,

这是我在 wamp 服务器中的 cakephp.conf

Alias /cakephp "d:/wamp/apps/cakephp/app/webroot" 

<Directory "d:/wamp/apps/cakephp/app/webroot">
   Options FollowSymLinks
   AllowOverride all
   Require local
</Directory>

这是 /cakephp 中的 .htaccess 文件(未更改任何内容)

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

</IfModule>

这是/cakephp/app 中的 .htaccess 文件(未更改任何内容)

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

</IfModule>

这是 /cakephp/app/webroot 中的 .htaccess 文件(已更改)

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

RewriteBase /cakephp

我刚刚添加了这一 我能够启动 url localhost/cakephp/index.php/posts/index

希望这将帮助您使用 WAMP 服务器开始使用 CakePhp

I had same issue and here is solution that worked for me

this is my cakephp.conf in wamp server

Alias /cakephp "d:/wamp/apps/cakephp/app/webroot" 

<Directory "d:/wamp/apps/cakephp/app/webroot">
   Options FollowSymLinks
   AllowOverride all
   Require local
</Directory>

This is .htaccess file in /cakephp (not changed anything)

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

</IfModule>

This is .htaccess file in /cakephp/app (not changed anything)

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

</IfModule>

This is .htaccess file in /cakephp/app/webroot (changed)

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

I just added line this line

RewriteBase /cakephp

After this I was able to launch url localhost/cakephp/index.php/posts/index

Hope this will help you to get started with CakePhp using WAMP Server

忆梦 2024-10-13 17:09:19

使用

  RewriteRule ^posts/(.*)  index.php/posts/index

use

  RewriteRule ^posts/(.*)  index.php/posts/index
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文