Welcome Guest, Not a member yet? Register   Sign In
force or remove trailing slash: duplicate cache issue
#1

[eluser]oliverkalen[/eluser]
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!
#2

[eluser]Ignacio[/eluser]
I have the same issue.

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

Sad
#3

[eluser]Leevi Graham[/eluser]
Did you ever find a solution to this?
#4

[eluser]Ignacio[/eluser]
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)
#5

[eluser]Leevi Graham[/eluser]
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.
#6

[eluser]mania[/eluser]
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.

Code:
<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>
#7

[eluser]Leon Stafford[/eluser]
I got rid of my trailing slashes with the above examples, but then it broke my FreakAuth Light login.... Sad
#8

[eluser]danoph[/eluser]
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:

Code:
<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!
#9

[eluser]RaZoR LeGaCy[/eluser]
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?
#10

[eluser]danoph[/eluser]
What error do you receive when you try to visit example.html? Most likely the file doesn't exist...




Theme © iAndrew 2016 - Forum software by © MyBB