We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

htaccess - remove index.php AND trailing slashes (Duplicate content)

Development and Programming

dstechroom's avatar
dstechroom
113 posts
15 years ago
dstechroom's avatar dstechroom

Hello -

We have removed the need for index.php within EE using (within .htaccess):

# strip index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

We noticed a duplicate content issue where some links to the same page had a trailing slash while others did not.

We added:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L]

However, this redirects WITH the index.php in the URL.

This behavior makes sense in that the actual request always has the index.php - We are just saying (via .htaccess) if it not there to add it to the request, but we are not enforcing it’s absence.

I believe I need some help making sure index.php is taken away if it is present in the request. (Use a redirect if it exists)

Perhaps this should be part of an extension rather than within htaccess? (In other words, part of the application code rather than web server config).

       
cjorgensen's avatar
cjorgensen
393 posts
15 years ago
cjorgensen's avatar cjorgensen

Have you seen: http://ee-garage.com/nsm-htaccess-generator

And reading his notes on the development might be helpful:

http://newism.com.au/blog/post/39/lg-htaccess-generator-removing-indexphp-from-your-expressionengine-site/

       
the3mus1can's avatar
the3mus1can
426 posts
15 years ago
the3mus1can's avatar the3mus1can

The order of rewrite rules is important. You need to put the:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^(.+)/$
RewriteRule ^(.+)/$  /$1 [R=301,L]

Above the:

# strip index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

Generally I try and keep the index.php removal rule last or anything that redirects before other rules that do not redirect - it just depends.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.