EllisLab text mark
Advanced Search
1 of 2
1
   
Fully qualified SEO URLs, how to be allowed to use them?
Posted: 22 July 2008 08:26 AM   [ Ignore ]
Joined: 2008-07-22
6 posts

I’m very new to CI so bare with me, but I have been reading all the docs and this forum but one thing, which might be trivial for some but of high value to us, is the ability to have fully qualified and optimized URLs.

This for example means that http://example.com/outsourcing-services/ is a better URL than just /services/, but php doesn’t allow the object names to contain ‘-’...and naming the controller file outsourcing-services.php while having the class be named ‘Outsourceservices’ doesn’t work either since then CI returns 404, file not found…

So how does one go about to have urls containing dashes? At highest level already. While still keeping the source neatly divided into the different controllers for different areas if wanted.

I’m sure it’s something easy I missed, but too much reading turns one blind sometimes.

Thanks in advance.

 
Posted: 22 July 2008 08:28 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-22
402 posts

Controller cannot have dash and all..No full proof solution yet.

you are allowed to used dash in next url segments.

 Signature 

Blogmer - Open source blogging software based on codeigniter
Blogmer Documentation
Web Design company and FREE PHP MySQL Webhosting

 
Posted: 22 July 2008 08:41 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2919 posts

There is a little function in the CI url_helper named url_title() which may help here.

Example:

url_title('some-url-string''underscore'); // produces 'some_url_string' 

The default option is ‘dash’ and will convert in the opposite direction if the second variable is omitted.

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 22 July 2008 09:02 AM   [ Ignore ]   [ # 3 ]   [ Rating: 0 ]
Joined: 2008-07-22
6 posts

Yash: Thanks for your fast response…I suppose one way would be to use mod_rewrite to splice a dash-one-dir-url to several sections…which kinda negates the point of not going from that to a normal file+parameter style right away…owell. :D

wiredesignz - 22 July 2008 12:41 PM

There is a little function in the CI url_helper named url_title() which may help here.

Example:

url_title('some-url-string''underscore'); // produces 'some_url_string' 

The default option is ‘dash’ and will convert in the opposite direction if the second variable is omitted.

Not sure how that would help out in this case. That is the inverted function, to create a dashed safe url, not handling a top-level dashed url.

 
Posted: 22 July 2008 09:14 AM   [ Ignore ]   [ # 4 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-10
2919 posts

Yes, sorry I use this method with _remap and a default_controller, it may not be applicable to you.

However, You could try str_replace() or preg_replace() in routes.php

 Signature 

URI Language Identifier | Modular Extensions - HMVC | View Object | Widget plugin | Access Control library

 
Posted: 22 July 2008 09:18 AM   [ Ignore ]   [ # 5 ]   [ Rating: 0 ]
Avatar
Joined: 2007-10-22
402 posts

yes wiredesignz that’s my point.

anyways by default its not possible we need some hack ..

 Signature 

Blogmer - Open source blogging software based on codeigniter
Blogmer Documentation
Web Design company and FREE PHP MySQL Webhosting

 
Posted: 22 July 2008 09:21 AM   [ Ignore ]   [ # 6 ]   [ Rating: 0 ]
Joined: 2008-07-22
6 posts
wiredesignz - 22 July 2008 01:14 PM

Yes, sorry I use this method with _remap and a default_controller, it may not be applicable to you.

However, You could try str_replace() or preg_replace() in routes.php

Well, yes, doing it hard in routing works…but it’s not very pretty.

Example:
$route[‘very-long-test’] = “welcome/testing”;

Then I know atleast. :D

 
Posted: 22 July 2008 11:10 AM   [ Ignore ]   [ # 7 ]   [ Rating: 0 ]
Avatar
Joined: 2007-06-06
141 posts

You could try a regex in the routing. I’m not an expert on regex, but something like this

$route['([a-z]+)-([a-z]+)'"$1$2"

This isn’t tested, so I’m unsure if it would work as intended. Maybe someone with more regex kung fu than I will help out.

Best,

Mei

 Signature 

Web Development in north Wales
mei.gwilym.net

 
Posted: 21 November 2008 04:40 AM   [ Ignore ]   [ # 8 ]   [ Rating: 0 ]
Joined: 2008-11-21
3 posts
Zarkow - 22 July 2008 12:26 PM

I’m very new to CI so bare with me, but I have been reading all the docs and this forum but one thing, which might be trivial for some but of high value to us, is the ability to have fully qualified and optimized URLs.

This for example means that http://example.com/outsourcing-services/ is a better URL than just /services/, but php doesn’t allow the object names to contain ‘-’...and naming the controller file outsourcing-services.php while having the class be named ‘Outsourceservices’ doesn’t work either since then CI returns 404, file not found…

So how does one go about to have urls containing dashes? At highest level already. While still keeping the source neatly divided into the different controllers for different areas if wanted.

I’m sure it’s something easy I missed, but too much reading turns one blind sometimes.

Thanks in advance.

How is it? Did anyone solved the issue?

 
Posted: 21 November 2008 04:49 AM   [ Ignore ]   [ # 9 ]   [ Rating: 0 ]
Joined: 2007-06-11
276 posts

negatory, you can’t have a dash in the controller name, i can’t really see why you would need to have it either.

 
Posted: 21 November 2008 04:51 AM   [ Ignore ]   [ # 10 ]   [ Rating: 0 ]
Joined: 2008-11-21
3 posts
ray73864 - 21 November 2008 09:49 AM

negatory, you can’t have a dash in the controller name, i can’t really see why you would need to have it either.

for SEO Friendly URL..

 
Posted: 21 November 2008 06:04 AM   [ Ignore ]   [ # 11 ]   [ Rating: 0 ]
Avatar
Joined: 2006-03-20
753 posts

Google have said that they treat underscores in urls exactly the same as a dash in a url. They said this some time ago (i think it’s on Matt Cutts blog).

So there you go, problem solved.

 
Posted: 21 November 2008 07:52 AM   [ Ignore ]   [ # 12 ]   [ Rating: 0 ]
Avatar
Joined: 2006-07-27
2617 posts

Meh.. Unfortunate you make that point, audiopleb. I don’t know why CI doesn’t just attempt to map dashed controller/function URI parameters to underscored class and class member function names. Well, actually, I do have a hunch why this isn’t done, but it still seems slightly ridiculous.

Three simple solutions remain. 1.) Abandon the dashes and adopt underscores, like audiopleb suggests. 2.) Override the necessary Router class member function(s) to make CI think of dashes as underscores. 3.) Lose the two-word URI param altogether. Just name the class “Outsourcing.” This last option is my favorite smile

 Signature 

Check out the Template Library
Oh yeah, I tweet, too (regarding CodeIgniter on occassion).

 
Posted: 13 August 2009 03:40 AM   [ Ignore ]   [ # 13 ]   [ Rating: 0 ]
Avatar
Joined: 2009-07-06
50 posts

So far, so good with overriding the Router library’s _set_request() method to change dashes found in the first two segments to underscores.

Attached is the MY_Router.php file (inside the .zip) that I’m using in my application/libraries/ directory and here is the addition to the method mentioned above:

for ( $i 0$i 2$i++ )
{
    
if ( isset($segments[ $i ]) && strpos($segments[ $i ]'-') !== FALSE )
    
{
        $segments[ $i ] 
str_replace('-''_'$segments[ $i ]);
    
}
 
Posted: 28 September 2009 11:58 PM   [ Ignore ]   [ # 14 ]   [ Rating: 0 ]
Joined: 2006-03-10
2 posts

Try my solution posted in a similar thread here:

http://ellislab.com/forums/viewreply/644012/

 
Posted: 29 September 2009 03:12 AM   [ Ignore ]   [ # 15 ]   [ Rating: 0 ]
Avatar
Joined: 2007-09-12
205 posts

switch to underscores.

 Signature 

Voltamp Media
Web: PHP, MySQL, PERL, HTML, CSS, Python, Javascript
Linux: FreeBSD, OpenVPN, SMB, SVN, C, Shell

 
1 of 2
1