Linda Antonsson
Linda Antonsson

Reputation: 283

Getting the trailing slash back in ExpressionEngine 2?

I have just upgraded from EE 1 to EE 2 and I am struggling with some of the changes. For example, the fact that EE no longer outputs a trailing slash on its urls is making a mess of a lot of my links where I had depended on constructions like EE generated url + additional segment. Finding and editing all places where I have done that would be a small nightmare considering the size and setup of my site. Is there any way to hack EE to get back the old behaviour?

Upvotes: 5

Views: 1211

Answers (2)

Parscale
Parscale

Reputation: 181

For some the trailing slash addition mentioned might cause conflicts with some forms. Adding the following to check if the request is a GET might be safer.

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

Upvotes: 6

lealea
lealea

Reputation: 563

There is an .htaccess solution to this, which I've used in my older EE sites because of this issue exactly.

Add trailing slash

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$
RewriteRule ^(.*)$ $1/ [L,R=301]

Source: http://devot-ee.com/articles/item/simple-htaccess-for-expressionengine-sites

However, since it's there by default in EE2, you might want to do the OPPOSITE and remove the trailing slash via .htaccess so you don't have to manually add/delete/whatever. If you decide on that, here's the code:

Remove Trailing Slash

RewriteCond %{HTTP_HOST} !^\.yoursite\.com$ [NC]
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]

Source: http://ee-spotlight.com/tips/a_standard_htaccess_file_with_expressionengine

Upvotes: 0

Related Questions