What are the chars that the url can include? |
[eluser]Leo78[/eluser]
Hey, I am creating a search in my website, the address has to be in this pattern: Code: www.domain.com/news/search/query/ The first pattern is when you are in page number 1 and the second pattern is when you are in page number 2+. So I created the following code in routs.php: Code: $route['news/search/(:any)'] = 'news_ci/sorting/search/$1/1'; The problem is for example the user types www.domain.com/news/query/char/ then he gets a SQL error, I'm pretty sure it's because I use slash in the end of the address. so instead writing (:any) I want to write a pattern which includes all (:any) pattern includes, without the slash.
[eluser]Aken[/eluser]
It probably doesn't have anything to do with the slash. First, your routes are backwards. The most specific ones should be first. Even if your URI matches the second example, it will always hit the first one and stop there. So flip those two around. Second, your number regex is excluding zero. So if a user ever tries to go to page 10 for example, the route won't match. I would just use (:num) instead, and make sure your controller checks that number. Third, it sounds like you're using something from the URI in your SQL query. Avoid doing that wherever possible - always make sure to put it in the format you need before using it in a query. If it needs to be a number, typecast it as an integer first.
[eluser]Leo78[/eluser]
1. Do you mean the first should be (:num) and then (:any)? In this case it's ok, but in other cases it's not what I prefer, because of SEO.. isn't there another solution? 2. Right. 3. Yes I am. (:num) - page number, (:any) search query. But I check it before I insert it to the SQL query so it's fine. Thank you, and if you have a solution to the order of the parameters please hit me.
[eluser]CroNiX[/eluser]
1. No, he means the route with 4 segments needs to come before the route with 3 segments. Code: $route['news/search/(:any)/(:num)'] = 'news_ci/sorting/search/$1/$2';
[eluser]Leo78[/eluser]
It doesn't solve the problem, but I think I have another direction. The route of my article page is: Code: $route['news/(:any)'] = 'news_ci/article/show/$1'; Code: http://www.domain.com/news/name-of-article/ Both of these address work, when I need that just address no.1 will work. Maybe there is a problem with the .htaccess file? I found this code in the net and used it (and don't see a problem with the code): Code: RewriteEngine On
[eluser]Aken[/eluser]
Has nothing to do with your .htaccess - it's all on your routes and application. $route['news/(:any)'] needs to come last, after the search routes. Again, MOST SPECIFIC routes FIRST, then in decreasing order of specificity.
[eluser]Leo78[/eluser]
[quote author="Aken" date="1345087048"]Has nothing to do with your .htaccess - it's all on your routes and application. $route['news/(:any)'] needs to come last, after the search routes. Again, MOST SPECIFIC routes FIRST, then in decreasing order of specificity.[/quote] I know, that what I've done. this is the full route: Code: // Tag, $tag, $page Again, when I enter to domain.com/news/article-name/bla/blu/ it recognizes that it should take 'article-name' as the parameter, but why doesn't it display error 404 because of the continue of the address? very strange for me. the address should be just domain.com/news/article-name/ I don't wanna the continue and don't know how to prevent it.
[eluser]Aken[/eluser]
Because you're using (:any). That means any characters, including /. If you don't want to include another slash, you have to specify only the characters that you're going to use in the segment for your titles. Something like this will use only letters, numbers and the dash (-) char. Code: $route['news/([a-zA-Z0-9\-]+)'] = 'news_ci/article/show/$1';
[eluser]Leo78[/eluser]
[quote author="Aken" date="1345092026"]Because you're using (:any). That means any characters, including /. If you don't want to include another slash, you have to specify only the characters that you're going to use in the segment for your titles. Something like this will use only letters, numbers and the dash (-) char. Code: $route['news/([a-zA-Z0-9\-]+)'] = 'news_ci/article/show/$1'; Good, that what I asked at the first post. thank you. I think it's a kind of bug, (:any) shouldn't include the $config['url_suffix'] char/s because then these cases causes (I thought at first that it doesn't include it, but I was wrong). don't you think?
[eluser]Aken[/eluser]
Definitely not a bug. :any means :anything, which should include, well, anything. Hah. Sorry you didn't understand that, but it's very literal. |
Welcome Guest, Not a member yet? Register Sign In |