This thread is a discussion for the wiki article: Remove index.php From URLs
   
3 of 4
3
Remove index.php From URLs
Posted: 12 June 2009 10:33 AM   [ Ignore ]   [ # 37 ]  
Grad Student
Rank
Total Posts:  62
Joined  05-11-2009

Gnarly one that, easy to fix though.

Set your logout code like this:

http://quinsa.net/index.php?ACT=10

Unless you REALLY want to do it without access index.php… in which case I’d have to take a closer look. It looks like you’re overdoing it a bit in the ReWrite code though.

You may be able to see what’s going on by putting “Logging” on like this:

RewriteLog "/path.to/some/directory/you/can/write"
RewriteLogLevel 9 

Logging goes from 0 (OFF) to 9 (ludicrous detail) and it can really help locate these faults.

I think this might work:

RewriteCond $^/(.*ACT=10)
RewriteRule ^(.*)$ /index.php/$1 [L] 

but it should give you somewhere to start.

Profile
 
 
Posted: 12 June 2009 10:52 AM   [ Ignore ]   [ # 38 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  247
Joined  06-25-2008

Thanks smidold!

I don’t mind setting the logout code to http://quinsa.net/index.php?ACT=10 ...Fine with me…. how do I set this, though? (and still have index.php removed for everything else?)

Nik

 Signature 

nickfoxall.com | ExpressionEngine Development in Hong Kong

Profile
 
 
Posted: 12 June 2009 12:03 PM   [ Ignore ]   [ # 39 ]  
Grad Student
Rank
Total Posts:  62
Joined  05-11-2009

Find this code:

<div id="homeclientlogin_en">
<
p>
<
a title="IMPORTANT! Remember to logout at the end of each session" href="http://quinsa.net/?ACT=10">Logout</a>
</
p>
</
div

which is probably slightly different in your template - but the link should be something like this

<a title="IMPORTANT! Remember to logout at the end of each session" href="http://quinsa.net/index.php?ACT=10">Logout</a

A better way, but depends if you’re in a user template or a system one - this won’t work for system templates is to put this into the HREF:

{site_url}index.php?ACT=10 
Profile
 
 
Posted: 12 June 2009 04:07 PM   [ Ignore ]   [ # 40 ]  
Research Assistant
RankRankRank
Total Posts:  354
Joined  11-20-2007
smidoid - 12 June 2009 02:33 PM

You may be able to see what’s going on by putting “Logging” on like this:

RewriteLog "/path.to/some/directory/you/can/write"
RewriteLogLevel 9 

Logging goes from 0 (OFF) to 9 (ludicrous detail) and it can really help locate these faults.

but it should give you somewhere to start.

Great tip. I’m not having any problems, but I’ve got a ton of RewriteRules and I didn’t know about this option. One thing to note. The mod_rewrite docs say:

Using a high value for Level will slow down your Apache server dramatically! Use the rewriting logfile at a Level greater than 2 only for debugging!

So, only set a high Level until you get your problems resolved. After that, either comment out the RewriteLogLevel line or set the level to 0 or a low number.

 Signature 

Tim


TVMCalcs.com - New and Improved! Now proudly powered by EE.

Profile
 
 
Posted: 12 June 2009 09:28 PM   [ Ignore ]   [ # 41 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  247
Joined  06-25-2008

Thanks smidoid, that worked a treat. I was stuck on the standard EE logout tag…

{path=LOGOUT} 

thinking it couldn’t be changed or altered in any way. But hardcoding the “.../index.php?ACT=10” link seems to do the trick.

Cheers,
Nik

 Signature 

nickfoxall.com | ExpressionEngine Development in Hong Kong

Profile
 
 
Posted: 13 June 2009 08:51 AM   [ Ignore ]   [ # 42 ]  
Grad Student
Rank
Total Posts:  62
Joined  05-11-2009

Good to be able to “pay it forward” Nik. Plenty of people on here have helped me out - and I’d be stuck without them!

Profile
 
 
Posted: 16 June 2009 06:31 AM   [ Ignore ]   [ # 43 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  257
Joined  01-30-2007

@Nick Foxall - note that other URLs and functionality that rely on ?ACT=X may still not work. I can’t offer a solution to the file and directory check but, using Leevi’s .htaccess generator (which uses a modified variant of the include method), I’ve found that adding this line fixes the problem:

RewriteCond %{QUERY_STRING} !^(ACT=.*)$ [NC] 
 Signature 

BridgingUnit (EE Pro) | EE Addons | Twitter: MarmaladeToday

Profile
 
 
Posted: 16 June 2009 10:46 AM   [ Ignore ]   [ # 44 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  247
Joined  06-25-2008

@BridgingUnit - thx for that. I’ll definitely try the include method on my next site.

Nick

 Signature 

nickfoxall.com | ExpressionEngine Development in Hong Kong

Profile
 
 
Posted: 28 October 2009 01:49 PM   [ Ignore ]   [ # 45 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  257
Joined  01-30-2007

And after a lot of banging my head against the desk I’ve just found that this code helps fix the various system path issues with the include method as outlined in the wiki. I expect it could be written more economically, but have added it as is.

# Fix queries for actions, urls and css in EE
RewriteCond %{QUERY_STRING} ^(ACT=.*)$ [NC,OR]
RewriteCond 
%{QUERY_STRING} ^(URL=.*)$ [NC,OR]
RewriteCond 
%{QUERY_STRING} ^(CSS=.*)$ [NC]   
RewriteRule 
^(.*)$ /index.php\?&%{QUERY_STRING} [L] 
 Signature 

BridgingUnit (EE Pro) | EE Addons | Twitter: MarmaladeToday

Profile
 
 
Posted: 05 November 2009 03:53 PM   [ Ignore ]   [ # 46 ]  
Grad Student
Rank
Total Posts:  32
Joined  10-04-2009

I have gotten the index.php to be removed, but how do I make the temporary index.html show up? I followed the Wiki, but the index.php is showing in its place.

RewriteEngine on

# During build - redirect root to static index page
RewriteCond %{REQUEST_URI} ^/$
RewriteRule http://www.example.com/index.html [R=302,L] 

<Files 403.shtml>
order allow,deny
allow from all
</Files>

<
Files .htaccess>
order allow,deny
deny from all
</Files>

#Turn on Compression
<IfModule mod_deflate.c>
<
FilesMatch "\.(html|htm|php|mp3|mp4|jpg|jpeg|gif|bmp|js|css|swf|png)$">
SetOutputFilter DEFLATE
</FilesMatch>
</
IfModule>

#Stop Displaying of directories
IndexIgnore *

#Change the default page
DirectoryIndex index.html

RewriteBase 
/

# Add a trailing slash to paths without an extension
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond 
%{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1[L,R=301]

#Force access to site without "www" to have "www"
RewriteCond %{HTTP_HOST} !^www\..* [NC]
RewriteRule 
^(.*) http://www.%{HTTP_HOST}/$1 [R=301,L]

#------------ ExpressionEngine Rewrite Rules ---------------#

# EE 404 page for missing pages
ErrorDocument 404 /index.php?/{ee:404}

# Simple 404 for missing files
<FilesMatch "(\.jpe?g|gif|png|bmp)$">
  
ErrorDocument 404 "File Not Found"
</FilesMatch>

RewriteCond $^(contact|embeds|links|menus|page\-comps|search|site|stylesheets|zz_site|P[0-9]{2,8}[NC]
RewriteRule 
^(.*)$ /index.php/$1 [L]

# Fix queries for actions, urls and css in EE
RewriteCond %{QUERY_STRING} ^(ACT=.*)$ [NC,OR]
RewriteCond 
%{QUERY_STRING} ^(URL=.*)$ [NC,OR]
RewriteCond 
%{QUERY_STRING} ^(CSS=.*)$ [NC]   
RewriteRule 
^(.*)$ /index.php\?&%{QUERY_STRING} [L]

RewriteCond 
%{QUERY_STRING} ^(CSS=.*)$ [NC]
RewriteRule 
^(.*)$ /index.php?/%1 [L]
RewriteCond 
$!^(cgi\bin|ee\-system\-files|images|includes|favicon\.ico|robots\.txt|index.php|index\.html[NC]
RewriteRule 
^(.*) /index.php?/$1 [L]

#------------ End ExpressionEngine Rewrite Rules ---------------# 

Any insight would be much appreciated.

Edit:
I figured it out. The code for the redirect to index.html wasn’t formed correctly - I also updated the Wiki.

# During build - redirect root to static index page
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule 
^(.*)$ "http\:\/\/www\.example\.com\/index\.html" [R=302,L] 
Profile
 
 
Posted: 09 November 2009 07:13 PM   [ Ignore ]   [ # 47 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  140
Joined  09-22-2009
bridgetstewart - 16 August 2008 05:22 PM

None of these are working for me on localhost using MAMP, which is allegedly supposed to be ready to go out of the box.

Mod-rewrite is loaded. Still nothing but 404 errors.

I’m having probs using this in Mamp also. I have localhost:8888/ee-starter/ as my root url. I’ve got the urls to work correctly, but when clicking the links to those urls - it just shows a 404 error page.

Has anyone else gotten it to work in mamp?

Profile
 
 
Posted: 01 December 2009 01:56 PM   [ Ignore ]   [ # 48 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  142
Joined  03-08-2006

I was having trouble with the include method and a slightly unconventional implementation of EE. Instead of structuring my site with template_groups {segment_1’s} per section, I did everything in the *site/index file. All references to purely nominal {segment_1’s} where dealt with and resolved within the same *site/index template.

However, removing the index.php with the include method either by hand or with Leevi’s extension simply returned a blank bage. Of course, there was no real /template_group/.

Solution is to hardcode the fuax-template groups (if you’re using Leevi’s addon) in the include rule:

RewriteCond %{REQUEST_URI} ^/({ee:template_groups}|faux-template1|faux-template2|members|P[0-9]{2,8}[NC] 
 Signature 

Seb Neerman

Profile
 
 
Posted: 10 December 2009 05:01 AM   [ Ignore ]   [ # 49 ]  
Summer Student
Total Posts:  1
Joined  12-10-2009

Hi i need a little bit of help.
I have three requirements first one is to fix the page name with extension and second is variable name fixing and third is the www because i want to make my URL more shortlike below url

OLD URL:
http://www.globalguideline.com/index.php?JScript=first_JavaScript

NEW URL (Required):
http://globalguideline.com/first_JavaScript

Please guide me,
Regards,
Hussain

Profile
 
 
Posted: 22 January 2010 04:17 PM   [ Ignore ]   [ # 50 ]  
Summer Student
Avatar
Total Posts:  12
Joined  10-22-2006

Hi,

I have used the following .htaccess to successfully remove the index.php?:

RewriteEngine on

RewriteCond 
$!^(favicon\.ico|pub|system|images|themes|robots\.txt|index\.php[NC]

RewriteRule 
^(.*)$ index.php?/$1 [L] 

Now the relative URLs in my HTML linking to CSS and images are not working. What they are doing is treating my template name(s) as directories but only when a slash ‘/’ exists in the URI such as:

This works:

www.mysite.com/subdir/template 

This does not:

www.mysite.com/subdir/template

The CSS is then being accessed incorrectly as in:

www.mysite.com/subdir/template/css.css 

instead of:

www.mysite.com/subdir/css.css 

I realize that I can make all of my paths absolute but I wonder if there is a more elegant way around this issue?

Thanks for any help. cool hmm

Profile
 
 
Posted: 06 March 2010 06:00 AM   [ Ignore ]   [ # 51 ]  
Summer Student
Total Posts:  12
Joined  03-05-2010

In the article it says:

To use Lodewijk plugin/workaround, simply download and install it, and add…

In my case:
{exp:replace find=”/index.php”}{pagination_links}{/exp:replace}


In others, this may be appropriate:
{exp:replace find=“index.php/”}{auto_path}{/exp:replace}


... in your pagination links, which solves the problem nicely.

However, I don’t exactly understand where I’m supposed to put the {exp ... code? I know it says “in your pagination links” but that’s not 100% clear to me.

Any help will be greatly appreciated.

Cheers,
Dan

Profile
 
 
Posted: 04 June 2010 10:16 AM   [ Ignore ]   [ # 52 ]  
Summer Student
Total Posts:  27
Joined  01-19-2010

Can anyone take a quick look at my code and offer any suggestions?  I can’t get it to work:

RewriteCond $^(weblog|member|search|forums|cool\-beans|starbucks\-coffee|P[0-9]{2,8}[NC]
  RewriteRule 
^(.*)$ /index.php?/$1 [L] 


cool-beans and starbucks-coffee are my template group names.  I added the \‘s to escape the dashes in the template names as per someones suggestion earlier.  I also added the ‘?’ to the /index.php?/$1 part.

Still having no luck getting this working.  :(

Profile
 
 
Posted: 19 June 2010 08:31 AM   [ Ignore ]   [ # 53 ]  
Summer Student
Total Posts:  25
Joined  03-11-2007

Hey all,

This is an easy one…

I’ve been developing a site that somehow got indexed by Google. Bummer!

Luckily the site is now live and ready to go but I need to reroute the old inks with a different index.php file name to the new one.

So by that I mean I’d like:

http://www.mysite.com/test.php/blog/my_blog_entry

to redirect to the following address using a 301 redirect:

http://www.mysite.com/blog/my_blog_entry

Please note the standard index.php file was changed to test.php whilst in development. It’s now been changed to index.php to go live.

What I need is to amend this:

[CODE]
RewriteEngine on
RewriteCond $1 ^(weblog|member|search|Forum_Name|blog|surface|portfolio|contact|about|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ /index.php/$1 [L]
[/CODE]

Which works for the site currently to incorporate the addition test.php urls currently in Googles search engine and 301 redirect them.

Does that make sense?

Thanks!

David

Profile
 
 
Posted: 27 July 2010 03:42 AM   [ Ignore ]   [ # 54 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  244
Joined  10-10-2007

Some times when default settings don’t work we use

### EXPRESSIONENGINE URL FIX - METHOD 1 - "EXCLUDE" LIST METHOD ###
Options +FollowSymlinks
RewriteEngine On
RewriteBase 
/
RewriteOptions MaxRedirects=10
RewriteCond 
$!^(images|system|themes|favicon\.ico|robots\.txt|index\.php[NC]
RewriteRule 
^(.*)$ /index.php?$1 [L] 

or

### EXPRESSIONENGINE URL FIX - METHOD 2 - "FILE AND DIRECTORY CHECK" METHOD ###
Options +FollowSymlinks
RewriteEngine On 
RewriteBase 
/
RewriteOptions MaxRedirects=10
RewriteCond 
$!\.(gif|jpe?g|png)$ [NC]
RewriteCond 
%{REQUEST_FILENAME} !-
RewriteCond 
%{REQUEST_FILENAME} !-
RewriteRule 
^(.*)$ /index.php?$1 [L] 
 Signature 

.
....................................................who we are...what we do...how you benefit

Profile
 
 
   
3 of 4
3