3

how to remove the index.php from the cakephp url? In order to access my forms folder, I have to give the url : http://localhost/cake_1_2/index.php/forms.

how do i remove that index.php?

I removed the .htaccess from the folders as mentioned in core.php and uncommented the App.baseUrl line. Yet,I'm not able to view the page without the index.php in the url.

3
  • Uh...why would you do that? index.php should not be visible by default, but now that you've removed .htaccess files it will most positively be seen. Commented Jul 15, 2009 at 10:49
  • Then shouldn't i remove those files? I dont want the index.php in my url. Commented Jul 15, 2009 at 11:11
  • 3
    If you want to use clean urls without index.php you need the .htaccess files, plus mod_rewrite must be enabled. Commented Jul 15, 2009 at 11:26

6 Answers 6

2

If you're using CakePHP with mod_rewrite on (to get pretty URL's) you can create new folders within WEBROOT and access files just fine.

Example:

Site/webroot/forms/form.php = http://www.sitename.com/forms/form.php

CakePHP's mod_rewrite is setup to check for existing files in WEBROOT and NOT pass them to index.php.

If you need to get up to folder outside of webroot you might consider playing with Symbolic links.

Sign up to request clarification or add additional context in comments.

Comments

1

Check the CakePHP Install guide section for mod_rewrite. Once enabled in Apache, the pretty URLs will just work. If you're not using Apache, you're stuck with ugly URLs.

1 Comment

Not true. You can use mod_rewrite and the short urls in lighttpd as well.
1

I had the same issue and had index.php in the URL. You're editing the wrong area in httpd.conf. Also, ensure your .htaccess files exist in: /.htaccess, /app/.htaccess and /app/webroot/.htaccess

Your httpd.conf should look something like this:

# Leave this area alone, CakePHP docs are wrong
<Directory /> 
   Options FollowSymLinks
   AllowOverride None
   Order deny,allow
   Deny from all
</Directory>

# Match this area
<Directory "/SomePath/app/webroot"> 
  Options Indexes FollowSymLinks MultiViews
  AllowOverride All   # Turn AllowOverride All on here
  Order allow,deny
  Allow from all
</Directory>

After doing this, I can easily create routes & access pages like: http://localhost/about/

Enjoy!

1 Comment

I notice that the directory you point to is the app/webroot of the cakephp folder structure. Wouldn't it be better to point to the base folder (/SomePath/), so that all .htaccess files in the cakephp project are visible? When I read the cakephp documentation for version 1.3, it tells me to create 3 .htaccess files, in path/, path/app/, and path/app/webroot/.
0

you can also check this mod rewrite tutorial here. it has general info which will be useful for url cleaning in many situations. there are also examples included.

Comments

0

Simply follow these following steps to verify it is there or not

  1. Check you root, app, webroot contains the actual .htaccess file.

  2. The apachee server have the following configuration:

    <Directory /> 
     Options FollowSymLinks   
     AllowOverride All#   
     Order deny,allow#   
     Deny from all
    </Directory>
    
  3. Also this line is uncammented:

    LoadModule rewrite_module libexec/apache2/mod_rewrite.so
    

Then restart your apache to see the changes

Comments

0

So, it should be ok? You already have mod_rewrite?

If mod_rewrite is correctly loaded, .htaccess files are in place and index.php still appears in links then it is most probably problem with core.php framework configuration file.

Problem cause

In my case it was problem with App.baseUrl configuration option:

Configure::write('App.baseUrl', env('SCRIPT_NAME'));

Solving problem

Here is how I fixed that problem (and few others with redirects) by commenting out following line from core.php:

// Configure::write('App.baseUrl', env('SCRIPT_NAME'));

or cake 3+ at config/app.php

//'baseUrl' => env('SCRIPT_NAME') 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.