# Remove index.php from url?

**URL:** <https://discourse.cakephp.org/t/remove-index-php-from-url/1429>\
**Category:** Need Help\
**Created:** [November 2, 2016, 10:14pm UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429 "2016-11-02T22:14:39Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [November 2, 2016, 10:14pm UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/1 "2016-11-02T22:14:39Z")

</div>

Hello,  
I want to remove the index.php from the url: [http://mywebsite/index.php/](http://mywebsite/index.php/).  
I use CakePHP pretty URLs, i removed all the .htaccess files:  
/.htaccess  
/app/.htaccess  
/app/webroot/.htaccess  
and uncommented the App.baseUrl on the core.php file.  
Thank you for your help!

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [November 3, 2016, 3:09am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/2 "2016-11-03T03:09:44Z")

</div>

You can control this with routing  
$routes-\>connect(’/’, [‘controller’ =\> ‘Controller Name’, ‘action’ =\> ‘index’]);

---

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [November 3, 2016, 3:40am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/3 "2016-11-03T03:40:16Z")

</div>

Hi thank you for your reply. here is my routes.php file.  
…  
Router::connect(’/’, array(‘controller’ =\> ‘reservations’, ‘action’ =\> ‘index’),array(‘language’ =\> ‘eng|fra’));  
Router::connect(’/searchcars’, array(‘controller’ =\> ‘reservations’, ‘action’ =\> ‘searchcars’));  
Router::connect(’/:language/:controller/:action/\*’,  
array(),  
array(‘language’ =\> ‘eng|fra’));  
Router::connect(’/:language/:controller’,  
array(‘action’ =\> ‘index’),  
array(‘language’ =\> ‘eng|fra’));

```
    	   Router::connect('/:language',
                           array('controller' => 'reservations', 'action' => 'index'),
                           array('language' => 'eng|fra'));

    	Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

...
```

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [November 3, 2016, 3:58am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/4 "2016-11-03T03:58:40Z")

</div>

So your [http://sgfrentcar.com/](http://sgfrentcar.com/) is working fine. Are you trying to build a link and after clicking on that you are redirected to [http://sgfrentcar.com/index.php/](http://sgfrentcar.com/index.php/)? This must be hard-coded and that’s why you are getting this URL. Just follow CakePHP docs properly.

---

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [November 3, 2016, 4:07am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/5 "2016-11-03T04:07:19Z")

</div>

yes all the pages on the website contains the index.php.  
here is how I’m adding the links on the menu:

\<?php echo $this-\>Html-\>link(\_\_('Cars', true), array('controller' =\> 'reservations', 'action' =\> 'searchcars')); ?\>

What do you mean by hard-coded? Can you explain me please?

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [November 3, 2016, 4:44am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/6 "2016-11-03T04:44:18Z")

</div>

In your home page your form action is “/index.php/” which is wrong. It should not like this, if you follow proper syntax you will get “/controller/action” or “/action”

---

<div class="post-metadata">

**Author:** ![domingosjunior87](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/domingosjunior87/32/175_2.png) [@domingosjunior87](https://discourse.cakephp.org/u/domingosjunior87)\
**Post date:** [November 3, 2016, 2:41pm UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/7 "2016-11-03T14:41:49Z")

</div>

You have to use all things that you removed. You need the .htaccess to do that

---

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [November 3, 2016, 3:20pm UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/9 "2016-11-03T15:20:42Z")

</div>

Hi thank you guys. Here is my .htaccess files before I removed them.  
They worked fine on localhost but on the server I had a 500 server error. That’s why I tried to find another solution by removing them.

.htaccess

RewriteEngine on  
RewriteRule ^$ app/webroot/ [L]  
RewriteRule (.\*) app/webroot/$1 [L]

app/.htaccess

RewriteEngine on  
RewriteRule ^$ webroot/ [L]  
RewriteRule (.\*) webroot/$1 [L]

webroot/.htaccess

RewriteEngine On  
RewriteCond %{REQUEST\_FILENAME} !-d  
RewriteCond %{REQUEST\_FILENAME} !-f  
RewriteRule ^(.\*)$ index.php [QSA,L]

---

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [November 3, 2016, 4:11pm UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/10 "2016-11-03T16:11:34Z")

</div>

yes but the others pages don’t work. if the link on the menu redirect me to [http://sgfrentcar.com/searchcars](http://sgfrentcar.com/searchcars) without index.php ,it doesn’t work.

---

<div class="post-metadata">

**Author:** ![ali](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/ali/32/123_2.png) [@ali](https://discourse.cakephp.org/u/ali)\
**Post date:** [November 4, 2016, 1:05am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/11 "2016-11-04T01:05:44Z")

</div>

Issues like these usually mean ModRewrite isn’t enabled on your server.

---

<div class="post-metadata">

**Author:** ![Tarek](https://avatars.discourse-cdn.com/v4/letter/t/cdc98d/32.png) [@Tarek](https://discourse.cakephp.org/u/Tarek)\
**Post date:** [November 4, 2016, 2:05am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/12 "2016-11-04T02:05:50Z")

</div>

Yeah maybe, I will call the hosting provider in this case. thanks

---

<div class="post-metadata">

**Author:** ![aavrug](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/aavrug/32/178_2.png) [@aavrug](https://discourse.cakephp.org/u/aavrug)\
**Post date:** [November 4, 2016, 3:14am UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/14 "2016-11-04T03:14:59Z")

</div>

Basically you changed so many things, so revert them first and then just follow the CakePHP docs and you don’t have to worry for anything else.  
There is no view file with extension `.php` it is only have `.ctp` in `CakePHP` so definitely if you are writing `index.php` that means you are doing wrong.

---

<div class="post-metadata">

**Author:** ![domingosjunior87](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/domingosjunior87/32/175_2.png) [@domingosjunior87](https://discourse.cakephp.org/u/domingosjunior87)\
**Post date:** [November 4, 2016, 12:15pm UTC](https://discourse.cakephp.org/t/remove-index-php-from-url/1429/15 "2016-11-04T12:15:25Z")

</div>

This **index.php** that he is talking about is in the root folder, not one **view file**.
