I am new to cakephp. This problem is my key development issue. I was trying to avoid asking this question on stack overflow because i have past experience of marks being deducted for noob questions. I researched solution for almost two days now on google, however, all the solutions are either not really useful or so unclear to a newbie like me. I need professionals from stack overflow to help me.
Basically, i installed xampp on mac, the path to my xampp in httpd.conf is
DocumentRoot "/Applications/XAMPP/xamppfiles/htdocs"
now i created a subfolder in htdocs named as cake, the installed cakephp in it. cakephp is working, but the problem is the image files and css are not displaying . I searched online and many suggested solution to change .htaccess . Here are my three .htaccess changes
.htaccess under cake
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake/
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
.htaccess under cake>app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /cake/app/
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
.htaccess under cake>app>webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /cake/app/webroot/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>
However image and css is still not working. Please help. Thank you very much
Have you enabled Apache's mod_rewrite?
Have you allowed individual folders to override server settings with .htaccess?
In your system conf file, make sure you have the following:
AllowOverride All
In the directory directive that covers your webroot.
Related
Currently working on a project and completed. Works fine in local. But when uploaded to server. It Doesnt work as it should be. CSS and JS and images are not linked. I checked all the .htaccess files in project folder and they seem fine. These are the codes in .htaccess files
in root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
in app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
in webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
These files were still same since uploaded to server. I also went through some articles and questions to make sure that am not messing with .htaccess files. Then i found this issue.
in local when i tried to open /localhost/project/app/Controller/UsersController.php in local it returns error as it should be
But when i tried the same in server
The page actually seems accessed. Since its controller no output is found but i can be sure the Controller is accessed directly. I cant figure out what kind of issue am going through. Am quite new to this. Any help will be appreciated.
Cake creates tmp files under tmp folder. You must need to give permission read/write to this folder. After making your code live please make 777 permission to your tmp folder and try to delete all those files under sub folders. It may work and please share your results. You will find tmp folder under app folder.
Your problem is in the in root .htaccess it should be like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ projectfolder/app/webroot/ [L]
RewriteRule (.*) projectfolder/app/webroot/$1 [L]
</IfModule>
The project works now(Have to contact support for enabling the mod_rewrite). I enabled
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
in config/core.php The problem is didnt have the mod_rewrite enabled in server. So enabling that in core supported the project to work without mod rewrite.
Thanks to
http://wwdj.wijndaele.com/getting-started-with-cakephp-without-mod_rewrite/
I had same problem, it was working on localhost but not on server, it was throwing 404 error.
It is because I had uploaded my website in subdirectory of sever root. I did many things to make it work but as I am using htaccess in root folder I found no solution on root level.
Finally I found a solution, edited existing htaccess of cakephp root folder and added "RewriteBase" after RewriteEngine on.
Full code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /name_of_the_subFolder
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Like if my project appear in 'xyz.com/one/two/cake/' then RewriteBase would be Rewritebase /one/two/cake/.
It worked for me.
I have a site done with cakePHP and I access to the sites there like:
http://example.com/site1
Which is converted to:
http://example.com/app/webroot/site1
As I've searched and seen here or searching here in stack-overflow this is the normal behaviour but I'd like that the user actually doesn't see the app/webroot bit.
Is that possible?
Here is my current .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/?(.*) http://www.example.com/$1 [R=301,NE,L]
# CakePHP part
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Thank you
If you followed all the instructions to install CakePHP, the URL without /app/webroot should work too. If it is not working, re-download all the .htaccess files from the CakePHP repo. There are three files.
To get rid of the /app/webroot, i.e. never see that path on any URL, you may edit or create a VirtualHost with a DocumentRoot pointing to the absolute path of your webroot.
Something like this:
<VirtualHost 127.0.0.2:80>
DocumentRoot /absolute/path-to/app/webroot
</VirtualHost>
This is not possible if you are on a shared server. If you are on a managed VPS or dedicated server, you need to contact your hosting. If it is unmanaged, you can do it yourself.
i have been working on setting up a url shortener with codeigniter i have everything working great and it works now with shortened urls like below.
http://example.com/shorten/i/znAS
ok what am looking to do is shorten it just to the i with my .htaccess access i am a complete newbie with .htaccess and have no idea how to do this is have been following this example here. http://briancray.com/posts/free-php-url-shortener-script/
which uses
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^shorten/(.*)$ shorten.php?longurl=$1 [L]
RewriteRule ^([0-9a-zA-Z]{1,6})$ redirect.php?url=$1 [L]
</IfModule>
Above is not really relevant for mine as its code igniter based. ok so shorten is my controller and i have a function within called i,
i have tried various combinations but nothing has worked for me yet below is my .htaccess.
Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^shorten/(.*)$ shorten/i/=$1 [L]
#RewriteRule ^(.*)$ index.php/$1 [L]
RewriteRule ^(.*)$ index.php?/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
whats there is currently breaking the website at the moment just looking and google at the mo but thought i would also add a post here as well thanks
With CI (or any framework for that matter), it is best to never touch the .htaccess file, unless you really need to. Take a look at the documentation with regard to working with the routes.php file in your application/config directory.
Try this route setting in the array:
'shorten/(.+)' => 'shorten/i/$1'
Please let me know if you have any problems with this.
currently when I click a link in on my website it is creating a url that looks like this
http://domainname.com/app/webroot/index.php/links
this causes the page to load incorrectly. if I edit the url by hand to look like this
http://domainname.com/links
everything loads correctly. My three .htaccess files look like this
/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app/
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
app/webroot/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
is there something I need to change in here? am I supposed to make these changes somewhere else? This site is hosted on godaddy's shared hosting. I don't know if that has anything to do with it.
UPDATE:
here is the link.
<?php echo $this->Html->link('Portfolio', array('controller' => 'images', 'action' => 'index'))?>
I've also tried removing the RewriteBase / line from all of the files. That didn't help.
also this is what is in my routes.php file.
Router::connect('/', array('controller' => 'posts', 'action' => 'index'));
Try taking out all the RewriteBase lines
Couple of things you can check:
mod_rewrite is available and working
Apache config allows
these options: Indexes MultiViews FollowSymLinks
RewriteBase in
your .htaccess actually rewrites to the correct dir if you have
multiple cakephp apps. E.g. I have to use RewriteBase
/~shaz/webapps/myapp/
Also there's loads of posts on google and even on stackoverflow so it might be worth ensuring you have the same "default" settings / environment as someone else, and working your way from there.
If all else fails, you can use the alternative "pretty" url setting provided in the config/core.php file.
I had to comment out the following line in the core.php file.
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
I forgot that I had to uncomment it to get things working on my development server.
I've got the following in .htaccess:
RewriteCond %{REQUEST_URI} !app/index\.php$
RewriteRule ^(.*\.htm)$ index.php?url=$0 [QSA,L]
Everyting works great but result URLs have empty $_POST.
I'm 100% sure that it's mod_rewrite bug, not HTML or PHP because when I change [QSA,L] to [L] it works great. But I really need QSA.
It happens at about 30% hostings so this may be some Apache config option.
What about modifying your rule in this way. Does it change anything?
RewriteRule ^(.*)\.htm$ index.php?url=$0.htm [QSA,L]
by default,.. maybe apache not enable mod_rewrite, try type this on your console
sudo a2enmod rewrite
sample my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I had exactly this issue. It works on one server then not the next. Annoying and time consuming to say the least!
After a lot of checking using this php:
foreach ($_REQUEST AS $key => $value) echo $value."<br>";
at the top of the index.php to check what values were being sent from the htaccess file, (and many other checks I will not go into!) I eventually found you need to specify "RewriteBase"
Adding RewriteBase / to the top of the htaccess file made it work on the all the servers I tried.
(also, remember to set to: RewriteBase /folder-where-file-is/
where "folder-where-file-is" is the location of the index.php file if in a sub-folder)
Hope it helps you - knowing this would certainly have helped me many many hours ago!