Welcome Guest, Not a member yet? Register   Sign In
Hello. I just posted a new "tutorial" about having "truly" SEO urls
#1

(This post was last modified: 03-23-2016, 08:15 AM by Avenirer. Edit Reason: forgot to put the url... :)) )

Hello, CI community.

A lot of people asked about having SEO friendly URLs, and even though we can set translate_uri_dashes to TRUE inside the routes.php, we still have a problem with "duplicate content", as urls with underscores still work at the same time as the urls with dashes. This tutorial, is not really a tutorial, but is a good way to invite people to look inside the CodeIgniter code.

If anyone has another solution, or if my solution is bad, please do tell me. Thank you.

http://avenir.ro/how-to-make-truly-seo-u...core-urls/
Reply
#2

Hi,

Interesting post - thanks.

As I was reading it and you got to the bit about

Quote:Then how do save ourselves from this SEO Armageddon? Well… Let us take a look at the Router.php inside the system/core.

I though, "oh no, don't start fiddling about with the core".

And then as I pondered through the code, still muttering to myself I got to:

Quote:So, this is the culprit… But what now? Should we simply modify it? No… NEVER MODIFY THE SYSTEM FILES IN CODEIGNITER!

That made me chuckle.

A very well written post.

I might give it a test with a small site sometime but doesn't having a canonical link on all your pages sort out all that SEO 'repeated content' problems anyway?

Best wishes,

Paul.
Reply
#3

Hello,
Thank you for sharing ,

In the code has some problems when applied .
Eg: base ( ' auth / edit_user / 1 ' ) --- > real url : localhost / authedit-user
not "/" and parameter

I think you should add a few lines of code :

line 54 :
Code:
$url .= str_replace( '_' , '-' , $segments[0] . '/');

and
Code:
if (count($segments) > 2)
{
   for ($i = 2; $i < count($segments); $i++)
   {
         $url .= '/'.$segments[$i];
   }
}
above : header('Location: '...........);
Reply
#4

I never like doing something with PHP that the server can do better. If you are on an Apache server with mod_rewrite enabled:


Code:
RewriteRule ^(.*)_(.*)$ $1-$2 [N,E=redirect:true]
RewriteCond %{ENV:redirect} ^true$
RewriteRule (.*) $1 [R=301]


By doing this you will just have a single redirect at the server level, and if CodeIgniter can't route to the URL it will just 404. No core extensions required.

Credit: https://www.geoffhayward.eu/2014/04/char...od-rewrite
Reply
#5

(03-23-2016, 08:32 PM)nguyenanhnhan Wrote: Hello,
Thank you for sharing ,

In the code has some problems when applied .
Eg: base ( ' auth / edit_user / 1 ' )  --- >  real url : localhost / authedit-user
not "/" and parameter

I think you should add a few lines of code :

line 54 :
Code:
$url .= str_replace( '_' , '-' , $segments[0] . '/');

and
Code:
if (count($segments) > 2)
{
   for ($i = 2; $i < count($segments); $i++)
   {
         $url .= '/'.$segments[$i];
   }
}
above : header('Location: '...........);

Thank you for looking at it. I just changed it. I usually do tutorials on fresh installs and I didn't think of testing it on something else than the Welcome controller  Wink .
Reply
#6

(03-23-2016, 09:46 PM)skunkbad Wrote: I never like doing something with PHP that the server can do better. If you are on an Apache server with mod_rewrite enabled:


Code:
RewriteRule ^(.*)_(.*)$ $1-$2 [N,E=redirect:true]
RewriteCond %{ENV:redirect} ^true$
RewriteRule (.*) $1 [R=301]


By doing this you will just have a single redirect at the server level, and if CodeIgniter can't route to the URL it will just 404. No core extensions required.

Credit: https://www.geoffhayward.eu/2014/04/char...od-rewrite

That is an interesting idea. Does it also work on the second segment of a url?
Reply
#7

(This post was last modified: 03-24-2016, 12:32 AM by Avenirer.)

(03-23-2016, 06:21 PM)PaulD Wrote: Hi,

Interesting post - thanks.

As I was reading it and you got to the bit about

Quote:Then how do save ourselves from this SEO Armageddon? Well… Let us take a look at the Router.php inside the system/core.

I though, "oh no, don't start fiddling about with the core".

And then as I pondered through the code, still muttering to myself I got to:

Quote:So, this is the culprit… But what now? Should we simply modify it? No… NEVER MODIFY THE SYSTEM FILES IN CODEIGNITER!

That made me chuckle.

A very well written post.

I might give it a test with a small site sometime but doesn't having a canonical link on all your pages sort out all that SEO 'repeated content' problems anyway?

Best wishes,

Paul.

The most important part in learning is the road Wink Regarding the "canonical links". You could do this, but you should first verify if the url is with underscores or not, no? I guess you could do this inside a MY_Controller...
Reply




Theme © iAndrew 2016 - Forum software by © MyBB