Using static URL's |
[eluser]Sweepee[/eluser]
Hi all, I'm trying to use static URL's in CodeIgniter, but can't find out how to do this! To explain my problems, I'll give you some examples of what I want: Code: /index.html Code: home Code: index Code: /contact.html Code: contact Code: index Code: /links.html Code: links Code: index I tried the following in Code: application/config/routes.php Code: $route["index.html"] = "home/index"; But this doesn't work! I always get the default controller when I surf to any of those URL's that I want. Can someone help me out here? Thanks for any help! Kind regards, Sweepee
[eluser]Isern Palaus[/eluser]
Take a look in your config.php, there is a variable to add a extension to all urls so if you add html it will be displayed .html. Then your route will be $route['index'] = "home/index"; and will be accessible by index.html.
[eluser]Sweepee[/eluser]
[quote author="Isern Palaus" date="1270010622"]Take a look in your config.php, there is a variable to add a extension to all urls so if you add html it will be displayed .html. Then your route will be $route['index'] = "home/index"; and will be accessible by index.html.[/quote] Thanks! I'll give it a try when I get back home! Cheers
[eluser]Sweepee[/eluser]
Hello again, I'm still experiencing problems configuring the routes as I desire them. The (relevant) configuration is as follows: /system/application/config/config.php Code: $config['base_url'] = "http://localhost/ci/"; /system/application/config/routes.php Code: $route['default_controller'] = "home"; /.htaccess Code: Allow From All All requests are redirected to index.php, except for JavaScript, CSS, text files and images. When I surf to http://localhost/ci/contact.html for example, I always get the homepage (home/index). Am I missing something here? Thanks in advance for any help!!! Kind regards, Sweepee
[eluser]cahva[/eluser]
Thats the expected behaviour because you are rewriting everything to plain index.php without segments(so index.php never gets your contact.html, links.html etc.). Try a different .htaccess. Something like this: Quote:RewriteEngine on That is from one of the sites I've developed. I usually place all css, images etc. in the assets folder but that should give you a clue how to do proper rewrite.
[eluser]Sweepee[/eluser]
My projects (with my needs) works with this HTACCESS file: Code: Allow From All It's working now for these URL's: /index goes to home/index /contact goes to contact/index But this doesn't work for /index.html and /contact.html... How can I set this HTACCESS? Don't I have to make a rule like: "redirect every URL that ends on .html to index.php without that .html" What do you think? Also, that setting in config.php... I don't think it's helping my out, because of the comments in the config: Code: /* It's only adding a suffix to all GENERATED URL's in CodeIgniter. Can be wrong though! Four happy days of CodeIgniter experience by now.
[eluser]cahva[/eluser]
It should be: Code: $config['url_suffix'] = ".html";
[eluser]Sweepee[/eluser]
[quote author="cahva" date="1270096321"]It should be: Code: $config['url_suffix'] = ".html"; Yup, noticed it before you replied. But it didn't work when I added the dot. This is what made it work completely (in /config/routes.php): Code: $route['default_controller'] = "home"; |
Welcome Guest, Not a member yet? Register Sign In |