I have a basic MVC structure with a restful uri design of:
mysite.com/appdir/:index/:controller/:action/
and I want to hide the index route parameter so my uri looks like:
mysite.com/appdir/:controller/:action/
My basic folder structure is:
appdir/
app/
-->Controller/
-->Model/
-->View/
config/
library/
public/
-->.htaccess
-->index.php
.htaccess
index.php
appdir/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ public/ [L]
RewriteRule (.*) public/$1 [L]
</IfModule>
appdir/public/.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [PT,L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 index.php
</IfModule>
I can't seem to hide the index, I've tried a number of rewrite rules and nothing seems to work. With CodeIgniter, I can usually add RewriteRule ^(.*)$ index.php?/$1 [L,QSA] and problem solved however I've been working on this for 3 hours with no success.
First, request path allways starts with /
so first rules should be written like this
RewriteEngine on
RewriteRule ^/(.*)$ public/$1 [L]
Then I guess in the public dir's htaccess you should use
RewriteBase /public
And finally - why not just set public as DocumentRoot of the webserver
and put all the rules to the single file? in your setup appdir/index.php is never accessible.
Related
I had shifted my cakephp website to a subfolder on AWS ubuntu machine. Site is working but CSS, Images and JS are not loading.
I am getting 404 not found error.
Not Found
The requested URL /demo/css/mscrollar/jquery.mCustomScrollbar.min.css was not found on this server.
Urls are working only with index.php.
Here is the htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /demo
RewriteRule ^media/(.*) http://%{HTTP_HOST}/files/timthumb.php?src=http://%{HTTP_HOST}/app/webroot/files/$1 [L,R=301]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Please help
You need to create two htaccess files. One in the webroot and one in the root path.
The one in the root (./.htaccess) should look like this (replace YOUR_PATH):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /YOUR_PATH
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
The one in the webroot folder (./app/webroot/.htaccess) should look like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I have a small question.
I have build a system and it is using a .htaccess to direct the traffic to the correct locations.
Now I have the following .htaccess data
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
///### (does not work.. this is a problem) RewriteRule (.*) app/template/ !page [L]
</IfModule>
The problem is actually that when I want to show a .css file located in /app/templates it also redirects to /core/
I tried to make an exception. However that does not really seem to work at my method.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
RewriteRule (.*) core/$1 [L]
RewriteRule (.*) app/template/ !page [L]
</IfModule>
This .htaccess gives a 500 error.
Could anyone tell me what I am doing wrong? And how I can make the exception work for the template directory?
TIAD!!
You should use:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ core/ [L]
# If the request is not for a valid directory
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) core/$1 [L]
</IfModule>
I'm trying to install CakePHP in www.domain.com/demo/realestate I changed .htaccess in root, app,webroot with ref from cakebook, S.O. and other websites. Most of them produced either 500 error or shown a blank page or 404 error.
My .htaccess code in each of those files are:
--in root--
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /demo/realestate
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 [L]
</IfModule>
I also tried to delete all .htaccess and write Configure::write('App.baseUrl', env('SCRIPT_NAME')); in app/config/core.php as per a suggestion in documentation but then it started taking demo as controller name and realestate as function name.
I request you to guide me to set it up!
There is no need to change in htaccess if you want to install cakephp in www.domain.com/demo/realestate. Just copy all cakephp files and folders in realestate folder with default htaccess and it'll work.
I recently uploaded a website on OVH made with the CakePHP Framework.
The fact is that whenever I want to go on a prefixed route, like /admin, or a plugin route, like /plugin_name, it's just duplicate the route on the URL.
For example, I'm on /admin/users/add, I click on the link to go on the index admin ( /admin ), the URL will be /admin/users/add/admin. For every prefixed route.
I've put all my folders directly on /www.
Here are my different .htaccess files:
On the root:
SetEnv PHP_VER 5
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
</IfModule>
Into the app folder:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
</IfModule>
And into the webroot:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [QSA,L]
</IfModule>
Furthermore, That did the same with my CSS / JS declarations in the <head>, and I noticed that if I don't use the CakePHP HtmlHelper, it works. But I can't do that for all my links / forms.
Thanks.
I'm new using cakephp, and I'm trying to set Friendly URLs for my site, but I'm having problems.
I've already made all the steps that the cakephp 2.3 Book says, and my apache configuration says that the mod_rewrite is being executed.
And when I enter the main page of cake, it says that the URL rewriting is not configured, and when I want to acces to my web I need to go throught www.mysite.com/index.php/controller/function and of course, i want this: www.mysite.com/controller/function, and if I try this route, it says that is not found in my server (and I have the controller and function created).
This are my .htacces files:
root directory:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
App 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 [QSA,L]
</IfModule>
I resolved It. in the file /etc/apache2/sites-enabled/000-default the directory was pointing to /var/www and my cakephp directory was in /var/www/html/myapp/cakephp. I changed it and now its working! :)