Welcome Guest, Not a member yet? Register   Sign In
Remove controller name from url
#1

[eluser]daka[/eluser]
I have followed tutorial on removing index.php,
but now I want to remove controller name with htaccess.

How can be this done with htaccess.
Hier is how it's now on my website:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /klub/

RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin

ErrorDocument 404 /index.php
</IfModule>

Or there is some easy sollution with php?
#2

[eluser]Madmartigan1[/eluser]
I'm struggling to understand what you're after...

Show an example url that you have, and what you want it to look like.
#3

[eluser]daka[/eluser]
Ok hier is example:
I have controller: user

so url is url/user/1

And what I want is url/user-1 or url/1 without user!
#4

[eluser]Madmartigan1[/eluser]
So which one do you want?

url/user-1 or url/1 without user?

I can't imagine that you would want http://example.com/1 to mean http://example.com/user/1

Please explain.
#5

[eluser]daka[/eluser]
Thnx for respond...hier is why:

It's seo technical stuff: all after slash is not importent like right before url.
tripadvisor is great example...there is no second slash!

now I have:
url/user/1
In one example I would like to have:
url/user-1

and with other controller posts I want to have:
url/title-of-one-post Now I have url/posts/title-of-one-post
#6

[eluser]Mike DeFelice[/eluser]
You can use routes I believe to achieve this.

User Guide
#7

[eluser]Madmartigan1[/eluser]
This is possible with routes:

Code:
// Route ALL requests through the posts controller
$route['(:any)'] = 'posts/$1';

// Route user-N through the users controller
$route['user-(:num)'] = 'users/$1';

Keep in mind, this will route ALL requests through the posts controller. It's the only way to do this without some sort of identifier. Consider something like url/p/this-is-the-post-title if you want to avoid routing nightmares.

You can also try dynamic routing, so that only posts that exist will be routed. Techniques for this will vary.

Those original urls are already quite SEO friendly, so I personally think you are splitting hairs and that this degree of optimization is probably not necessary.

Also, since I'm not 100% sure the order of routes parsed by CI, try changing the order if that doesn't work.
#8

[eluser]Bart v B[/eluser]
And don't forget to look at the _remap() function.
Then you have the option to create one controller that routes to user for example..

Code:
&lt;?php

public function _remap($user)
{
  if($user == $this->uri->segment(1) )
  {
    $this->method();
  }
  else
  {
    $this->index();
  }
}

public function index()
{
  // just showing off the default page
}

public function method()
{
  // show user info
}




Theme © iAndrew 2016 - Forum software by © MyBB