Codeigniter Multiple Slashes in Between URI Segment after Mod Rewrite

Just a note and reminder. When I tried to remove index.php using .htaccess in Codeigniter, I noticed double slashes in between the URI segment so it looked like this:

http://localhost/project//read/post/2

After I looked at my code, I realized that I often use site_url like this

<?php echo site_url(); ?>/read/post/<?php echo $post->id ;?>

The code above is actually valid and works just fine if you don’t use  .htaccess to remove index.php. But when you use mod_rewrite in .htaccess, you’ll notice that you have double slashes in between the URI segment.

To correct this annoying anomaly, you have to alter your code so it become something like this

<?php echo site_url('read/post/'.$post->id); ?>

It will remove the extra slashes when you use mod_rewrite and works just fine if you decide to opt out .htaccess.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:

Logo WordPress.com

You are commenting using your WordPress.com account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s