• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
url rewrite problem

#1
[eluser]RpR[/eluser]
Hi,

I am facing this problem.

I have a controller called welcome.php which is called as the index page.
Thanks to the url rewrite I have a clean url like this:
Code:
http://localhost/cvp/
instead of
Code:
http://localhost/cvp/index.php

Now when I add another function (Like test) in welcome.php the url is
Code:
http://localhost/cvp/welcome/test/

Is there a way to remove the welcome to?

My current htaccess file is:
Code:
RewriteEngine on
RewriteBase /cvp/
RewriteCond $1 !^(index\.php|img|js|css|favicon\.ico|robots\.txt)
RewriteRule ^(.*)$ /cvp/index.php/$1 [L]

Thanks for any input.

#2
[eluser]Derek Allard[/eluser]
You bet. Set your config['index_page'] to '' (empty quotes) and use CI's anchor() function.

#3
[eluser]RpR[/eluser]
It is blank. It needs to be blank for the rewrite.

#4
[eluser]Derek Allard[/eluser]
and the anchor funtion is automatically adding in "welcome"? Could you share your code?

#5
[eluser]LuckyFella73[/eluser]
If you have a fresh installation of codeigniter
where the default controller in routes.php is still set
to "welcome" and you load the page, the first URI segment
is not displayed (I don't know how CI hides it).
As soon you click at a link, the controller name
is displayed as URI segment 1 and the function name
is added as URI segment 2 (if you call any other function then index).
In your case
Code:
http://localhost/cvp/welcome/test
If you just want to have "test" in your url
Code:
http://localhost/cvp/test

you will have to add a controller named "test" (controller/test.php
with the class name "Test"

Did you mean that?

#6
[eluser]fesweb[/eluser]
I think you're looking for "routes" functionality.

In your config/routes.php file:
Code:
$route['test/:any'] = "welcome/test/";
$route['test'] = "welcome/test/";

Something like that should do it.

#7
[eluser]RpR[/eluser]
Shall test this but then I loose the ability to add it on the fly. Then I should edit 2 files. The main controller class and then the routes file.

#8
[eluser]fesweb[/eluser]
You can also remap the controller, which gives a different result, but you might be able to think your way into a solution which works for you.

First function after the _constructor():
Code:
if ($method == 'index')
    {
        $this->test();
    }
    else
    {
    $this->$method();
    }
But I think you would have to roll your "welcome" function into your test funtion to make this work for you.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.