Welcome Guest, Not a member yet? Register   Sign In
URL question
#1

Good day for everyone! I have a bit dumb question. Imagine, we have controller

PHP Code:
class Test {

     public function 
index()
     {
          echo 
'Some page';
     }

     public function 
page()
     {
          echo 
'Some page 2';
     }



So i can call index by url like test/index or i can set routing for that $route['test'] = 'test/index';

So we have that one page(content) have two links! test and test/index and if i write them to address bar result page will the same. So common question is how handle this kind of situations?

For example, maybe i need check in index method do i have second segment equal 'index' and redirect to just 'test' or something?

PHP Code:
public function index()
{   
     if(
$this->uri->segments(2) === 'index'redirect('test');


How do you handle stuff like this? I think this is all about SEO and so on, what would be the best?
Reply
#2

The best thing to do for SEO purposes would be to make your site's links consistent. If you want to use /test, then don't link to /test/index. Most search engines will simply start with the first page and crawl their way through the links on your site until they can't find any new links. If another site links to your site, they'll usually use a link they received from you/your site.

Most of your visitors won't sit there and mess with the URL in their browser to see if they can get alternatives to work, and even those who do will not make much of an impact on your SEO.

Most of the people who do try alternative URLs are using a script to try to find sites with specific vulnerabilities they can exploit, and they're looking for specific URLs, most of which are going to return 404s, anyway (unless you like messing with people who are specifically looking for servers to attack, in which case you will probably find plenty of people to mess with if you specify routes for wp-admin, wp/wp-admin, old/wp-admin, blog/wp-admin, and wordpress/wp-admin (seeing a pattern here?)).

If specific URLs end up giving you SEO problems, the easiest method of dealing with it is usually in your rewrite configuration, so it can be handled without even loading CodeIgniter, making the response faster for the user and the overall load on your server lower.
Reply
#3

(This post was last modified: 10-08-2015, 08:12 AM by scion.)

Thank you for extend answer! So if I understood correctly - just use everywhere link "/test" (even if we have possiblity to use "/test/index" and it works) and all will be ok? Just want sure that I dont need to do some extra work like I mention before with redirect.

Many thanks!
Reply
#4

(This post was last modified: 10-08-2015, 08:32 AM by mwhitney.)

Most of the time, yes. If you never link to /test/index, it only exists if someone else links to it (or guesses it). While you wouldn't want to depend on this for security, it's rarely an issue for SEO.

If you do find that someone's linking to a specific index page and this is causing SEO problems for your site, you should redirect that URL in your web server configuration, if possible, rather than doing it within CodeIgniter (and definitely use a client redirect, as an internal redirect won't help with SEO).

Edit: You can also set the canonical URL in the page's head if you're really concerned about this. Then, even if someone does link to /test/index, you've indicated to the search engines that /test should be used instead.
Reply
#5

Wow, so much useful staff I read more and more. Very thank you for this! I understand all very clear.

So problem that I need set some redirect staff in webserver configuration which will be for all sites that exist on this server.

Or maybe set some htaccess file inside my example site, thats it! So trick with canonical links very useful, thanks for this.

And last thing - what means client redirect vs internal?

Thanks again, all I understand, just clear some things and I think I done already this problem with your help!
Reply
#6

So if any would be interesting how this problem resolves

#instead of test put name of your default controller
RewriteRule ^(test(/index)?|index(\.php)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
Reply




Theme © iAndrew 2016 - Forum software by © MyBB