Welcome Guest, Not a member yet? Register   Sign In
Dashes instead of underscores in url
#1

[eluser]AntonioAntar[/eluser]
Hello friends

I'm using the latest version of codeigniter, I can't remember which one was it but I know it is the latest

there is an option in routes where you can change the underscores into dashes in the url, which I want to do for SEO purposes

I have the following in my routes.php

$route['translate_uri_dashes'] = TRUE;

Which does the job, as I can access all my url's using dashes

However, I can also access all my pages using underscores as well, so as it stands now all controllers can be accessed using underscores and dashes as my url

example: localhost/mainpage/test-page and localhost/mainpage/test_page both work

Is this the way it works? and which version will show up when I upload the website to the server? is there a way I can make the url's work only if they use dashes instead of underscores and not both?

Best regards
#2

[eluser]Tpojka[/eluser]
That's way cookie crumbles.
You would need to manage .htaccess file in order you want visitor is not able to set 'underscore url'.
Something like
Code:
Redirect /controller_method_argument /controller-method-argument
Find propper explanation on this page.
Maybe you should also check Regular Expression to be able to set wild card.
#3

[eluser]boltsabre[/eluser]
I had the same thing on my CI website.

I just made a hack fix in my index file (but I'm sure you could do it in .htaccess, but I'm not great with that).

Basically I get the entire URL and run a string search on underscores.
If any where found I then did a string replace (replacing underscores with dashes) and then do a 301 redirect to the new "dashes" URL.
That keeps the urls all fully dashed and stops any problems with duplicate content.




Theme © iAndrew 2016 - Forum software by © MyBB