Part of the EllisLab Network
   
3 of 3
3
How can I remove index.php part from URL
Posted: 30 November 2011 11:14 PM   [ Ignore ]   [ # 31 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  03-25-2011

Sorry it’s delayed.. Testing now.. Feedback soon.

Profile
 
 
Posted: 01 December 2011 12:00 AM   [ Ignore ]   [ # 32 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  03-25-2011

I WIN!

Okay, wow was this a hassle, but more of a server set-up I didn’t complete. I am using Ubuntu 11.4. I think it’s 4.. Anyways, open up your command line, PuTTY is what I use to remotely run it..

Anyways, first things first, make sure mod_rewrite is on. It was off for me.

Steps: For me, I log into a user, so I have to cd ../../ to get to the base. Type ls to make sure you’re in the directory with /var and /etc.

Run this command to enable mod_rewrite:
sudo a2enmod rewrite

Restart Apache:
sudo /etc/init.d/apache2 reload

(I think here I restarted the whole server instead of just apache… had to walk to the box.. messed something up.. lol)

Now, The main problem lies within the rules of allowing .htaccess override.

We’ll need to edit a file:
sudo nano /etc/apache2/sites-available/default

I had to edit this in two spots.

<VirtualHost *:80>
      ServerAdmin webmaster@localhost

      DocumentRoot /var/www
      <Directory >
          Options FollowSymLinks
          AllowOverride All
      </Directory>
      <Directory /var/www>
          Options Indexes FollowSymLinks MultiViews
          AllowOverride All
          Order allow,deny
          allow from all
      </Directory>

Where it is bold, it says None, change it to All. It was the second one that did it, but I already changed the first one, so it’s staying at All. lol

If you’re not familiar with Nano, press Ctrl-X to exit, Y to save.

Restart apache again with the command above, and it works! smilesmile:):)

My file structure: http://regal/sebserver htacc.ess was in the sebserver folder.

.htaccess:

RewriteEngine On
RewriteBase 
/sebserver/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
^(.*)$ index.php/$1 [L] 

If this does not work, let me know smile

 

Profile
 
 
Posted: 01 December 2011 05:53 AM   [ Ignore ]   [ # 33 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  188
Joined  05-11-2011

The only thing I didn’t was sudo nano /etc/apache2/sites-available/default bit.

I’ll do it when I get back home today and let you know. Thanks for all those you have been doing.

Profile
 
 
Posted: 01 December 2011 03:24 PM   [ Ignore ]   [ # 34 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  188
Joined  05-11-2011

YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE
EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE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SSSSSSSSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS
.........................................................................
.........................................................................
.........................................................................
.........................................................................

Hey regal, happy xmas. Someone has to give you a medal.
It was ALL about AllowOverride ALL

Thank you very much. What else can I say.

Profile
 
 
Posted: 01 December 2011 04:23 PM   [ Ignore ]   [ # 35 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  03-25-2011

Haha. Glad it worked. smile Now get coding on your project! I’m always looking for some good developers wink lol

Profile
 
 
Posted: 13 December 2011 12:06 PM   [ Ignore ]   [ # 36 ]  
Summer Student
Avatar
Total Posts:  10
Joined  12-12-2011

RewriteEngine On
RewriteBase /sebserver/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

would you like to explain the .htaccess?
I don’t understand very well.

Profile
 
 
Posted: 14 December 2011 06:53 AM   [ Ignore ]   [ # 37 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  206
Joined  03-25-2011

Second line sets a base url, sometimes needed, most the time not. If you want all files to point to a subdirectory, then set the base accordingly.

Third and fourth line check to see if the (f)ile or (d)irectory exist. If they don’t, then it will process the rule on the 5th line. If the file, or directory exists, then it will try to access that. This allows you to access items outsite your application folder.

Profile
 
 
Posted: 15 December 2011 08:18 PM   [ Ignore ]   [ # 38 ]  
Summer Student
Avatar
Total Posts:  10
Joined  12-12-2011

thank’s for your explaination…
I want to ask what is the rule on the 5th line.?

Profile
 
 
Posted: 15 December 2011 08:30 PM   [ Ignore ]   [ # 39 ]  
Sr. Research Associate
Avatar
RankRankRankRankRank
Total Posts:  2537
Joined  02-19-2009

if the requested file or directory doesn’t exist, send the request to CI (index.php)

 Signature 
Profile
 
 
Posted: 16 December 2011 04:23 AM   [ Ignore ]   [ # 40 ]  
Grad Student
Avatar
Rank
Total Posts:  86
Joined  10-30-2008

Without wanting to hijack this thread or start a new one i have an issue with index.php

my site is working fine and have removed index.php as normal but with one small problem.

visit - http://www.mysite.com/index.php/controller
goes to - http://www.mysite.com/controller

BUT if i visit

http://www.mysite.com/index.php

i want it to default to

http://www.mysite.com

instead, at the moment it stays on

http://www.mysite.com/index.php

## add www
RewriteCond %{HTTP_HOST} ^mysite.com
RewriteRule 
^(.*)$ http://www.mysite.com/$1 [R=301,L]

## remove trailing slashes
RewriteCond %{HTTP_HOST} ^(www.)?mysite\.com[NC]
RewriteRule 
^(.+)/$ http://www.mysite.com/$1 [R=301,L]

# Application specific
RewriteCond $!^(index\.php|assets|robots\.txt|favicon.\ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_FILENAME} !-d
RewriteRule 
^(.*)$ index.php/$1 [L] 

Im sure its something simple as ever

 

Profile
 
 
Posted: 16 December 2011 04:30 AM   [ Ignore ]   [ # 41 ]  
Grad Student
Avatar
Rank
Total Posts:  86
Joined  10-30-2008

Ok, just tested this again properly and can see that

visit - http://www.mysite.com/index.php/controller
stays on - http://www.mysite.com/index.php/controller

i thought it would redirect to

http://www.mysite.com/controller

visiting http://www.mysite.com/controller works fine though too.

So, i guess the question is can we completely remove the index.php even if someone types it in or the visit comes from a link containing it

Profile
 
 
Posted: 16 December 2011 09:44 PM   [ Ignore ]   [ # 42 ]  
Summer Student
Avatar
Total Posts:  10
Joined  12-12-2011

if the requested file or directory doesn’t exist, send the request to CI (index.php)

thank’s for your explanation..

Profile
 
 
Posted: 17 December 2011 01:57 AM   [ Ignore ]   [ # 43 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1114
Joined  11-28-2007
fwebs - 16 December 2011 04:30 AM

Ok, just tested this again properly and can see that

visit - http://www.mysite.com/index.php/controller
stays on - http://www.mysite.com/index.php/controller

i thought it would redirect to

http://www.mysite.com/controller

visiting http://www.mysite.com/controller works fine though too.

So, i guess the question is can we completely remove the index.php even if someone types it in or the visit comes from a link containing it

You can do this, but I wouldn’t recommend it. Mysite.com/index.php is a valid URL and a valid file. You don’t want to redirect away from it in the event that someone enters that link.

Profile
 
 
Posted: 30 December 2011 09:04 AM   [ Ignore ]   [ # 44 ]  
Summer Student
Total Posts:  3
Joined  02-27-2011

Thanks regal, have been fighting with that for ages

Profile
 
 
   
3 of 3
3
 
‹‹ import adres e-mail      Create CSV Report ››