htaccess for cakephp [duplicate] - .htaccess

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
.htaccess for cakephp
I use this code for htaccess
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Inside this folder,
root/
app/
app/webroot
But not work
My live path is http://www.jacksonwebservices.co.uk/

you should be running with the default cake supplied .htaccess files. there is nothing wrong with them for the most part. it seems like the .htaccess files are not readable by the webserver.
check your logs for more info.

Do you have that same .htaccess file in each of those directories? You need a different one in each of them. See http://book.cakephp.org/#!/view/917/Apache-and-mod_rewrite-and-htaccess for details.

I am guessing you are having the same Rewrite base problem that I recently had, put this in your .htaccess instead:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Sometimes it doesn't work without the 'RewriteBase' line at the top.

EDIT: DO AS JUHANA SAYS: Make sure you have the correct htaccess files in the correct locations. They are all different. If it is as you describe, webroot is redirecting to itself redirecting to itself redirecting ...
Does your website have mod_rewrite enabled?
Create a file that contains just this:
<?php
phpinfo();
?>
and save it as phpinfo.php in your document root (public_html, www or whatever)
Navigate to that page (http://www.jacksonwebservices.co.uk/phpinfo.php) and search the page for 'rewrite'. If you can't find it it's not enabled and CakePHP will not work in the default mode. See the manual for alternatives: http://book.cakephp.org/view/917/Apache-and-mod_rewrite-and-htaccess
You may need to contact your hosting to get it enabled or to find out how to do it yourself.

Related

htaccess and Laravel

my domain
example.com
I want install Laravel to subfolder
example.com/my_app
when I pass the link
example.com/my_app/public - I see page "You have arrived", but I want see this page without segment "public".
I want make something like I do when I use Laravel not in subfolder, like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I edited .htaccass file in base folder (example.com) :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/my_app
RewriteRule ^(.*)/$ my_app/public/$2 [L,R=301]
</IfModule>
after this when I pass at example.com/my_app/ I redirects to example.com/my_app/public and I see page "You have arrived", but this is redirect (R=301) and if I delete flag R=301 - I see page with "Whoops, looks like something went wrong."
I am three days looking solutions in this website, but ...
tell me what am I doing wrong.
Thank.
The entry point for all requests to a Laravel application is the public/index.php.
for further info you can go to this link.
Assuming you are using Apache, You would need to configure virtual host for this as you would need to point example.com/my_app to your laravel/public/index.php. directory.

Using .htaccess and mod_rewrite

I'm having some mod_rewrite problems with my .htaccess..
RewriteBase /folder
RewriteEngine on
Rewrit­eRule ^(.*)$ basic.p­hp?­url=$1 [L]
Above is what I'm currently using. However, I have no idea what I'm doing to be honest as I'm just cycling through the internet trying to figure this out.
Basically, for my website, if you type in
www.domain.com/folder/xxx/
I want it to basically be www.domain.com/folder/basic.php?url=xxx.
For some reason, all that does is cause a 404 error :/
So can someone please politely point me in the right direction?
Ok, I will explain using your htaccess.
RewriteEngine on
Turn on the Rewrite Module to enable URL rewriting
RewriteBase /folder
Rewrite the Base Directory to directory name folder
RewriteRule ^folder/(.*)$ basic.php?url=$1 [L]
Remap every request make using the folder/***** to basic.php?url=********
Note: RewriteEngine On Should be the first statement on your case
RewriteEngine on
RewriteBase /
RewriteRule ^folder/(.*)$ folder/basic.php?url=$1 [L]
This is more of a problem with regexs than .htaccess files.
http://httpd.apache.org/docs/current/mod/mod_rewrite.html
http://www.regular-expressions.info/

PHP page access without extension and variable

How can I create a PHP page system that we access without .php extension and without ?page= variable?
There's a simple exemple:
http://www.exemple.com/portfolio/1
Instead of:
http://www.exemple.com/portfolio.php?id=1
It would be great for me because I'm a web designer and this is a thing I never did. So it would be good to know this! Also I will use this in my website.
you would need the following in your .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*[^/])/?$
RewriteCond %{DOCUMENT_ROOT}%1.php -f
RewriteRule .+ %1.php [QSA,L]
You're looking for mod_rewrite.
RewriteEngine On
RewriteRule ^/profile$ /account.php?profile [L]
Create .htaccess file in your web root and enter following.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^account/([0-9]+)$ account.php?id=$1
OR
See mod_rewrite, in case URL rewriting, if you trying to do such.
You can use multiviews, or better and more used: mod_rewrite module from apache. It can be via a .htaccess file where you create rewrite rules like
RewriteEngine On
RewriteRule ^(.*)?(.*)$ /$1.php?Action=$2 [L]

How do I use .htaccess to change the structure of my website?

I'm doing some reorganizing on my web server and would like to change the way my structure works. Currently, everything is stored at the lowest level so that when I access my site the url looks like this:
www.example.com
www.example.com/page1.php
I have many pages in my site and i would like to move them out of the main folder. eg.
www.example.com/folder/
www.example.com/folder/page1.php
however, I would like for users not to see the /folder/ section of the url. In other words, when a user visits my site, I want him to navigate to:
www.example.com/page1.php
www.example.com/myfolder1/page1.php
www.example.com/myfolder2/page2.php
www.example.com/anyfoldername/anypagename.php
but actually be at
www.example.com/folder/page1.php
www.example.com/folder/myfolder1/page1.php
www.example.com/folder/myfolder2/page2.php
www.example.com/folder/anyfoldername/anypagename.php
I want the url to show without the /folder at all times.
Is there a way to do this with the .htaccess file?
You can easily do this using mod_rewrite. For example:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^page1\.php$ /folder/page1.php [L]
NOTE:
This is to be placed in .htaccess in your website root folder. If placed elsewhere some small tweaking may be required.
UPDATE:
RewriteCond %{REQUEST_URI} !^/folder/
RewriteRule ^(.*)$ /folder/$1 [L]
RewriteEngine On
RewriteBase /
RewriteRule ^([^/]*)$ folder/$1 [L]

CakePHP and .htaccess in shared hosting environment

Greetings!
I have CakePHP based app on shared hosting I wonder if there's a way to clean up the url through .htaccess. What bugs me is that I have to have index.php in it or I get a 404:
project.com/index.php/controller/method
Initially I was getting a 404 error no matter what and my host admin ended up setting RewriteEngine off and this is what it looks like now
<IfModule mod_rewrite.c>
RewriteEngine off
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
Is there fix for this without the .htaccess? As it is right now, does it pose any type of security risk?
Thanks
You need three .htaccess files :
/.htaccess
/app/.htaccess
/app/webroot/.htaccess
If the one you pasted in your question is the one at the root of your website, that's probably where your problem comes from. These directives file would rewrite URLs to project.com/webroot/, which doesn't exist. It should redirect to project.com/app/webroot/, which will in turn rewrite to index.php?url=$1 (relative to project.com/app/webroot/).
I'm not pasting the files here; the three of them are available in the CakePHP releases as well as in the Book: http://book.cakephp.org/2.0/en/installation/url-rewriting.html (check the 3rd item in the page).
Are you sure the mod_rewrite module is enabled on your shared hosting?

Resources