virtual subdomain with htaccess |
[eluser]harmstra[/eluser]
I try to create a virtual subdomain, but no workie workie. When i put this in htaccess, Code: RewriteCond %{HTTP_HOST} ^subdomain[NC] things work fine. test is a physical subdir, and the contents of /test/index.html show up when i point the browser to subdomain.domain.com. Important: the addressbar keeps the subdomain.domain.com, while it shows www.domain.com/test/index.html So far, so good. Now i want to do the same thing, but redirect to a CI controller Code: RewriteCond %{HTTP_HOST} ^subdomain[NC] Then i get a Internal Server Error, because of a redirect loop. So i add 1 line. Code: RewriteCond %{HTTP_HOST} ^subdomain[NC] Then everything works fine, subdomain.domain.com shows the contents of www.domain.com/controllername. But the annoying thing is, the url in the address bar changes to www.domain.com/controllername Is there a way to avoid this?
[eluser]TheFuzzy0ne[/eluser]
That's what it's meant to do when you specify a host name as the target. If you want an internal redirect, just specify the directory relative to the htaccess file.
[eluser]harmstra[/eluser]
Unfortunatly, that is not the case, as you can see in the first piece of code. Here i specify the hostname + path and the visible address is not rewritten.
[eluser]TheFuzzy0ne[/eluser]
OK, I think we might be getting out wires crossed here, so I'll try explaining again. Code: RewriteCond %{HTTP_HOST} ^subdomain[NC] Code: RewriteCond %{HTTP_HOST} ^subdomain[NC]
[eluser]harmstra[/eluser]
Maybe that's how things are in theory. This is how tings are on my server in real life /test is a physical directory Code: RewriteCond %{HTTP_HOST} ^subdomain[NC] /test is a NOT a physical dir, but a controller Code: RewriteCond %{HTTP_HOST} ^subdomain[NC] So what's the difference? I think the problem is this The code used for CI Code: RewriteCond $1 !^(index\.php|images|robots\.txt|src|ext) In the first case, the dir exists, in de second it doesn't So in the second case, the above RewriteRule will be executed, in the first case it won't.
[eluser]TheFuzzy0ne[/eluser]
In your first example, please substitute [QSA,L] for [R]. Does it redirect the browser then? If it doesn't, them the rule is not matching.
[eluser]harmstra[/eluser]
The URL does not change, the browser says Found The document has moved here. Additionally, a 403 Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
[eluser]harmstra[/eluser]
But when i remove this Code: RewriteCond $1 !^(index\.php|images|robots\.txt|src|ext) it gets redirected to www.domain.com/test
[eluser]Jelmer[/eluser]
I do it by first redirecting to the directory from the root .htaccess file: Code: RewriteCond %{HTTP_HOST} ^sub.domain.com$ And then put a .htaccess file with the /subdomain/ directory that takes care of the CI rewriting. Like the htaccess in your code above (#7), just remember that the htaccess in your subdomain directory has a rewritebase of "/" and not "/subdomain/". |
Welcome Guest, Not a member yet? Register Sign In |