Welcome Guest, Not a member yet? Register   Sign In
Pretty URLS and trailing slashes
#1

[eluser]Unknown[/eluser]
Hi,

I'm new to CI and have recently converted my old ASP site (BOOOOO) into CI (YAY!) and I have to admit I found it very simple to do and fairly painless.

I'm left with one little issue though, for some reason on a few URLs on my site I get a trailing slash and I can't seem to get rid of it, odd thing is though this slash only seems to appear on index pages on my site which are serving dynamic content.

I know this problem of trailing slashes has been posted many times before, as I have spent about 2 days looking for a solution, but each one i try doesn't seem to work.

I'm figuring this is some kind of routing or .htaccess issue but I'm not able to track down the problem.

Just to let people know where I am at...

I have built my application and moved my system folder out of htdocs for security purposes and then adjusted index.php accordingly.

My views folders are set up like so...

views
- blog
- index.php
- article.php
- some_photos
- index.php
- photo.php

In my routes.php I have rules like the following

Code:
$route['blog/:num'] = "blog/index";
$route['blog/:any/:num'] = "blog/article";

$route['some-photos'] = "some_photos";
$route['some-photos/:any/:num'] = "some_photos/photo";

My .htaccess file has the following rules:

Code:
RewriteEngine On

RewriteCond $1 !^ (index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

I can't for the life of me work out where I am going wrong!

By using fixes I have found on the net such as this one:
Removing Trailing Slashes From Your URL

I can get the following kind of result:
www.sitehere.com/blog/index.php/blog
Which removes the slash on the urls I want them gone from but it adds back in index.php which I really don't want.

Can anyone help or has anyone else come across this problem?

I am guessing the only other thing I can do is to force every url to have a trailing slash but this isn't something I really want to do if I can help it.

Thanks in advance
#2

[eluser]developer10[/eluser]
[quote author="konj75" date="1249331241"]Hi,

I'm new to CI and have recently converted my old ASP site (BOOOOO) into CI (YAY!) and I have to admit I found it very simple to do and fairly painless.

I'm left with one little issue though, for some reason on a few URLs on my site I get a trailing slash and I can't seem to get rid of it, odd thing is though this slash only seems to appear on index pages on my site which are serving dynamic content.

I know this problem of trailing slashes has been posted many times before, as I have spent about 2 days looking for a solution, but each one i try doesn't seem to work.

I'm figuring this is some kind of routing or .htaccess issue but I'm not able to track down the problem.

Just to let people know where I am at...

I have built my application and moved my system folder out of htdocs for security purposes and then adjusted index.php accordingly.

My views folders are set up like so...

views
- blog
- index.php
- article.php
- some_photos
- index.php
- photo.php

In my routes.php I have rules like the following

Code:
$route['blog/:num'] = "blog/index";
$route['blog/:any/:num'] = "blog/article";

$route['some-photos'] = "some_photos";
$route['some-photos/:any/:num'] = "some_photos/photo";

My .htaccess file has the following rules:

Code:
RewriteEngine On

RewriteCond $1 !^ (index\.php|images|robots\.txt|css)
RewriteRule ^(.*)$ /index.php/$1 [L]

I can't for the life of me work out where I am going wrong!

By using fixes I have found on the net such as this one:
Removing Trailing Slashes From Your URL

I can get the following kind of result:
www.sitehere.com/blog/index.php/blog
Which removes the slash on the urls I want them gone from but it adds back in index.php which I really don't want.

Can anyone help or has anyone else come across this problem?

I am guessing the only other thing I can do is to force every url to have a trailing slash but this isn't something I really want to do if I can help it.

Thanks in advance[/quote]

in CI user guide you have something about URI segment slashes (many options to choose from) - i think it's contained in URI Class
#3

[eluser]Unknown[/eluser]
Thanks for replying cold_fusion.

Isn't that class for retrieving data from the string? Not for removing or altering the sting?

I'm trying to remove a trailing slash from the URL in the address bar of my browser.
#4

[eluser]developer10[/eluser]
[quote author="konj75" date="1249351213"]Thanks for replying cold_fusion.

Isn't that class for retrieving data from the string? Not for removing or altering the sting?

I'm trying to remove a trailing slash from the URL in the address bar of my browser.[/quote]

as i understand it, you can retrieve that particular segment which has the trailing slash, then apply
some of this or similar (this is taken from this link, so explore it) http://ellislab.com/codeigniter/user-gui...s/uri.html

=============================================================
Code:
$this->uri->slash_segment(n)

This function is almost identical to $this->uri->segment(), except it adds a trailing and/or leading slash based on the second parameter. If the parameter is not used, a trailing slash added. Examples:
$this->uri->slash_segment(3);
$this->uri->slash_segment(3, 'leading');
$this->uri->slash_segment(3, 'both');

Returns:

1. segment/
2. /segment
3. /segment/
==============================================================

hope this helps
#5

[eluser]rdjs[/eluser]
I think the uri library is for retrieving a segment of the current URL with the bonus of stipulating if you want slashes. This is great if you are trying to extract that data to use in your application however I think that konj75's problem is more to do with how the url is re-written by either Apache or the Application in the browser address bar.

As the OP says...
Quote:I can get the following kind of result:
www.sitehere.com/blog/index.php/blog
Which removes the slash on the urls I want them gone from but it adds back in index.php which I really don’t want.

They can almost get the desired result but at the expense of including the index.php in the url too. I should think that this is a .htaccess issue and I am sure there is a .htaccess genius could suggest a solution.




Theme © iAndrew 2016 - Forum software by © MyBB