Welcome Guest, Not a member yet? Register   Sign In
Help with .htaccess - Subdomain
#1

[eluser]Enéas Gesing[/eluser]
Hi,

I have on my site the following URI structure:

http://www.site.com/search/category/cate...egory-name

I want to use this URI structure:

http://categories.site.com/category-name...egory-name

How can I do this? How is the best way to redirect users from this new URI to CI URI structure (http://www.site.com/controller/function/params)?

Thanks!
#2

[eluser]Henry Weismann[/eluser]
For:
http://categories.site.com/category-name...egory-name

Will category-name be a controller and sub-category-name be a function or will these be variables you want to pass to one function. I would imagine these are variables you want to pass to one function.....

Then you want to put codeignitor in the http://categories.site.com sub domains directory or point the sub domain to wherever codeignitor is and create a controller and function to take those two variables and return the right page/data.

The controller and function can be named anything but if the controller is named categories and use use category for the function name you could create an htaccess something like:

Code:
RewriteEngine on
RewriteCond RewriteCond %{HTTP_HOST} ^categories.site.com$
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/categories/category/$1 [L]

If this is not going to be the only thing that codeignitor does then you will have to worry about using two different domain names which can get more complicated but can be done.
#3

[eluser]Enéas Gesing[/eluser]
Hi Henry.

I already have current URI structure on my site:
http://www.site.com/search/category/cate...-category/...

Search is my controller, category is the function and (sub)categories I get using $this->uri->segment(n) because of categories hierarchy.

I need for a "forward" from http://categories.site.com/category-name...-category/... to that structure.

I think that one or two simple RewriteCond will solve this, but my knowledge about this is limited.

Thanks in advance.
#4

[eluser]Henry Weismann[/eluser]
So point your new subdomain to the folder that ci is in...ask your webhost how.

Then use the following in your htaccess:

Code:
RewriteEngine on
RewriteCond RewriteCond %{HTTP_HOST} ^categories.site.com$
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/search/category/$1 [L]

The above redirect will only run if the http host is the sub domain so everything from the normal part of the site will not be affected.

And in your config use a switch to set the base url to either the sub domain or the regular domain based on what is the current host in the request.

Thats the quick and dirty way.
#5

[eluser]Enéas Gesing[/eluser]
Thanks,

You solved my problem.
#6

[eluser]Ajeesh[/eluser]
Hi,

I have on my site the following URI structure:

http://www.site.com/index.php/controller...tent-title

I want to use this URI structure:

http://content-title(read from db).site.com/controller/function-name/‘content-title(read from db)’

please replay




Theme © iAndrew 2016 - Forum software by © MyBB