Part of the EllisLab Network
   
 
force or remove trailing slash: duplicate cache issue
Posted: 21 January 2008 11:51 PM   [ Ignore ]  
Summer Student
Total Posts:  7
Joined  01-21-2008

I would like to force consistency in my URI’s to prevent duplicate cache entries

http://website.com/uri/here
http://website.com/uri/here/

Visiting both of these pages will create 2 separate cache entries. My mod_rewrite in htaccess currently looks like:

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

Is there a mod_rewrite solution to this? or will it need to be done through CI?
I can deal with/without the trailing slash - whichever is easier.

Thanks!

Profile
 
 
Posted: 09 June 2008 08:50 PM   [ Ignore ]   [ # 1 ]  
Grad Student
Rank
Total Posts:  72
Joined  01-02-2008

I have the same issue.

http://website.com/uri/here -> cache (not by CI)
http://website.com/uri/here/ -> no cache, works fine!

:(

Profile
 
 
Posted: 22 August 2008 03:50 AM   [ Ignore ]   [ # 2 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006

Did you ever find a solution to this?

 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

Profile
 
 
Posted: 22 August 2008 04:14 AM   [ Ignore ]   [ # 3 ]  
Grad Student
Rank
Total Posts:  72
Joined  01-02-2008

I fix this disabling eAccelerator. But I’m not completely sure if this is the best/right solution, but without eAccelerator, the problem is gone. (Sent with my iphone in bed)

Profile
 
 
Posted: 22 August 2008 04:35 AM   [ Ignore ]   [ # 4 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1336
Joined  01-24-2006

I implemented this for ExpressionEngine and it seems to be doing the trick.

# Add Slash
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteCond $1 ^(members|contact|cms-customisation|site|ee-support|wp-content|P[0-9]{2,8}) [NC]
RewriteRule ^(.*)$ $1/ [L,R=301]

Basically if its not a file, directory or one of my template groups I redirect to the exact same thing with a trailing slash.

 Signature 

EE-Garage.com - All my ExpressionEngine 2 Addons!


EE2 - NSM Better Meta - SEO Meta & XML Sitemap Generator
EE2 - NSM Live Look - Real entry previews


Newism - Newcastle - ExpressionEngine Experts

Profile
 
 
Posted: 17 November 2008 01:46 PM   [ Ignore ]   [ # 5 ]  
Summer Student
Avatar
Total Posts:  12
Joined  11-15-2006

I think I have this working to both force a trailing slash and get rid of the index.php but can someone explain what I did here by trial and error?

I am pretty sure its important to not have multiple options on how to get to a page for SEO etc.

<IfModule mod_rewrite.c>
    
RewriteEngine On
    RewriteBase 
/

    
# this adds trailing slash
    
RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_URI} !(.*)/$
    
RewriteRule ^(.*)$ $1[R=301,L]

    
# this gets rid of index.php
    
RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_FILENAME} !-d
    RewriteRule 
^(.*)$ index.php/$1

</IfModule
Profile
 
 
Posted: 16 February 2009 03:20 AM   [ Ignore ]   [ # 6 ]  
Grad Student
Rank
Total Posts:  56
Joined  02-07-2009

I got rid of my trailing slashes with the above examples, but then it broke my FreakAuth Light login…. :(

 Signature 

Leon Stafford
China Dropship Partial CI
China Quality Control Migrating WP to CI

Profile
 
 
Posted: 04 June 2009 08:37 PM   [ Ignore ]   [ # 7 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  118
Joined  06-21-2007

I’ve been looking for a solution for a while now, and this one works perfectly on my mediatemple server hosting http://graphicleftovers.com (built in codeigniter + wordpress for blog), as is without any editing:

<IfModule mod_rewrite.c>
    
RewriteEngine On
    RewriteBase 
/

    
# this adds trailing slash
    
RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_URI} !(.*)/$
    
RewriteRule ^(.*)$ $1[R=301,L]

    
# this gets rid of index.php
    
RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond 
%{REQUEST_FILENAME} !-d
    RewriteRule 
^(.*)$ index.php/$1

</IfModule

Thanks a lot @mania!

 Signature 

GraphicLeftovers.com - Professional Stock Graphics and Images for Less, powered by CodeIgniter

Profile
 
 
Posted: 01 January 2011 07:48 PM   [ Ignore ]   [ # 8 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  174
Joined  07-14-2007

Sorry to bring this thread back but:
http://www.example.com/example works and goes to http://www.example.com/example/
http://www.example.com/example.html breaks

How do I fix this?

 Signature 

Hell Horror - CodeIgniter Community for Horror Fans

Profile
 
 
Posted: 03 January 2011 01:22 PM   [ Ignore ]   [ # 9 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  118
Joined  06-21-2007

What error do you receive when you try to visit example.html? Most likely the file doesn’t exist…

 Signature 

GraphicLeftovers.com - Professional Stock Graphics and Images for Less, powered by CodeIgniter

Profile