Welcome Guest, Not a member yet? Register   Sign In
Url rewriting
#1

[eluser]Unknown[/eluser]
Hi everyone, I have some problems with code igniter url rewriting.
I want my users have personnals urls like that: http://username.mydomain.com
I have set DNS wildcard and in my vhost configuration.

My problem is for Rewrite rules.

Usually (without CI), I do something like that:
RewriteRule (.*) index.php?user=%1 [L]. So, http://test.domain.com was the same as http://domain.com?user=test

But with CI, it's not possible to do the same because i can't pass variable with index.php?variable=whatever

If I do something like RewriteRule (.*) http://mydomain.com/user/%1 [L], it works but it redirects and I want to keep username.mydomain.com in adress bar instead of mydomain.com/index.php/user/username.

Does someone have any idea to do that?
Thanks a lot :-)
#2

[eluser]TheFuzzy0ne[/eluser]
Doing it the first way, you need to make sure you have query strings enabled. If you don't need to use query strings for your entire site, I'd suggest sticking to your second method. If you want it to redirect internally, you need to omit the URL, so:
Code:
RewriteRule (.*) index.php?/user/%1 [L]

should probably do what you want. Adding the URL makes the redirect external, which can be really handy for confirming that it's rewriting the URL as you'd expect it to.




Theme © iAndrew 2016 - Forum software by © MyBB