Welcome Guest, Not a member yet? Register   Sign In
Trailing slash & redirect() problem solved with .htaccess
#1

[eluser]dmitrybelyakov[/eluser]
Today i decided to fix the annoying trailing slash problem.
Reading through the forum i found no exact answer: all aproaches had drawbacks ad problems with URI and redirect() functions. Someone tried to modify the CI core libaries and use regular expressions. But all you really need to do is change .htaccess.

So i decided to do it myself and now share with you.

What we are doing:

1. Eliminate index.php from URL
2. Redirect all calls without trailing slash to the proper URL with a slash.

It's quite smart and does all URI handling with exceptions for the real existing resources like folders and files. So here it goes:

Change the config.php:

Code:
$config['base_url']    = "/";
$config['index_page'] = "";

And put this .htaccess to your root folder.
Code:
RewriteEngine on

# Fix the trailing slash problem

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



# Redirect all calls to index.php

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



Hope that would be of any help.




Theme © iAndrew 2016 - Forum software by © MyBB