Welcome Guest, Not a member yet? Register   Sign In
mod_rewrite changing URI segment order
#3

[eluser]Resorath[/eluser]
[quote author="Aken" date="1341383782"]What's the end goal here? Ideally, you shouldn't need to add additional .htaccess rules - CI's routes should take care of most things. You should explain the actual functionality behind it, and maybe we can suggest something better or help fix your solution if it's appropriate.[/quote]

Hi Aken,

The end goal is an application that generates websites with an URL that appears more natural.

Each entry function inside of a controller will have the site name as the first parameter to act accordingly based on the site that was selected

Code:
public index($site)
{
   ...
}

for example, a gallery and a catalog controller for each site (with three user's different sites) would normally look like:

http://www.example.com/gallery/index/mysite/
http://www.example.com/gallery/index/someothersite/
http://www.example.com/gallery/index/athirdsite/

http://www.example.com/catalog/index/mysite/
http://www.example.com/catalog/index/someothersite/
http://www.example.com/catalog/index/athirdsite/

etc..

However, it makes more sense from a user standpoint (each user having their own website) to have the site name come first, as the "root" of the URL. So the URL would look like:

http://www.example.com/mysite/gallery/index
http://www.example.com/mysite/catalog/index

http://www.example.com/someothersite/gallery/index
http://www.example.com/someothersite/catalog/index

http://www.example.com/athirdsite/gallery/index
http://www.example.com/athirdsite/catalog/index

(and ideally, able to omit the "index" part of the URL)

I tried using routing, this was my solution (which does work):

Code:
$route['(:any)/gallery/(:any)'] = "gallery/$2/$1";
$route['(:any)/catalog/(:any)'] = "catalog/$2/$1";

However this has some issues.

First, each controller now needs to have an entry in the routes file. This removes any elegance from the design of the controllers.

Second, this may have adverse effects if additional parameters need to be passed to functions. This also may impede the ability to remove the "/index/" from the path for the default index function.


Messages In This Thread
mod_rewrite changing URI segment order - by El Forum - 07-03-2012, 10:26 PM
mod_rewrite changing URI segment order - by El Forum - 07-03-2012, 11:36 PM
mod_rewrite changing URI segment order - by El Forum - 07-04-2012, 09:51 AM
mod_rewrite changing URI segment order - by El Forum - 07-04-2012, 10:24 PM
mod_rewrite changing URI segment order - by El Forum - 07-05-2012, 10:16 AM
mod_rewrite changing URI segment order - by El Forum - 07-05-2012, 11:44 AM



Theme © iAndrew 2016 - Forum software by © MyBB