0
RewriteRule ^(new-york/new-york-city/chelsea/10001) index.php [L]

The above code does not work. It gives me a 404 error in Codeigniter. However, the following code does work.

RewriteRule ^(new-york/new-york-city/chelsea/10001) http://anywebsitehere.com/ [L]
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198
user1426594
  • 125
  • 1
  • 6
  • Where is your .htaccess file located? If it's in a weird location... you might want to consider using [RewriteBase](http://stackoverflow.com/questions/704102/how-does-rewritebase-work-in-htaccess). – summea Apr 08 '13 at 18:34
  • The .htaccess file is located in the main directory. – user1426594 Apr 08 '13 at 18:35
  • Also doesn't work. It keeps trying to load a page called new-york via CodeIgniter pattern of controller/action and giving me a 404. – user1426594 Apr 08 '13 at 18:52
  • Actually, why is it that you are using a rewrite rule like this? :) – summea Apr 08 '13 at 18:55
  • We're working with a marketing guy and he wants pretty URLs. Basically, he wants (new-york/new-york-city/chelsea/10001) to load a page full of listings/places that are in New York. So the easiest way is to use our existing Search functionality which leaves an ugly url such as search/param1=ASD&param2=ASDF. – user1426594 Apr 08 '13 at 18:57
  • Ah; if that's the case... would you want to make the rewrite rule a bit more flexible (or dynamic)? – summea Apr 08 '13 at 18:59
  • For now, I want to handcode everything. This is a script we bought off the internet and it's full of bugs and glitches. The idea is to get some users on it and then eventually build our own system. – user1426594 Apr 08 '13 at 19:04
  • 1
    You should use a standard CI .htaccess file, and use routes to catch these. – Aken Roberts Apr 08 '13 at 19:30
  • @Cryode I actually went that route and was told to use a .htaccess file. Check my profile history. – user1426594 Apr 08 '13 at 19:44
  • Yeah, @Cyrode is correct, you should be using routes for this. – kittycat Apr 08 '13 at 20:54

1 Answers1

0

The RewriteRule just rewrites to index.php, which calls the default route, if you have one setup. If you want to go to your search, you must rewrite to the search controller and method and pass the pretty URL or part of it as arguments

RewriteRule ^new-york/new-york-city/chelsea/10001 index.php/search_controller/search_method/$0 [L]

This will call in application/controllers/search_controller.php the method search_method with the pretty URL as arguments

search_method('new-york', 'new-york-city', 'chelsea', '10001');
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198