Lumio Posted January 27, 2008 Share Posted January 27, 2008 Hi! I got a subdomain for example foo.example.com Now I want to redirect it to example.com/foo/ How can I do this with mod_rewrite? thx Quote Link to comment Share on other sites More sharing options...
madmax Posted January 27, 2008 Share Posted January 27, 2008 Try (example which will handle all top level domains and sites - remove wildcard backrefs and make specific as required) RewriteEngine On #RewriteLogLevel 9 #RewriteLog logs/rewrite.log RewriteCond %{HTTP_HOST} ^(.*)\.(.*)(\..*)$ [nc] RewriteRule (.*) http://%2%3/%1$1 [L] For redirect change the last line - [L] to [L,R] (Tested only on local machine) Quote Link to comment Share on other sites More sharing options...
madmax Posted January 27, 2008 Share Posted January 27, 2008 Actually, duh!!, snip the L, LR bit. Of course you should always need a redirect remapping to http:// However I tested locally and both forms worked OK A non-wildcard TLD form with wildcard subomain would be (say for localhost.com) ... RewriteEngine On #RewriteLogLevel 9 #RewriteLog logs/rewrite.log RewriteCond %{HTTP_HOST} ^(.*)\.localhost\.com$ [nc] RewriteRule (.*) http://localhost.com/%1$1 [L,R] Tested on simulated localhost.com #Faked hosts entry 127.0.0.1 graphics.localhost.com 127.0.0.1 localhost.com Quote Link to comment Share on other sites More sharing options...
Lumio Posted January 28, 2008 Author Share Posted January 28, 2008 It doesn't work for me. Even the log doesn't change. RewriteEngine On RewriteLogLevel 9 RewriteLog rewrite.log RewriteCond %{HTTP_HOST} ^mubix\.citrosaft\.com$ [nc] RewriteRule (.*) http://dev\.citrosaft\.com/index.php/Mubix [L,R] Yesterday or some more I tried to use RewriteEnginge On RewriteRule ^(.*)$ index.php?title=$1 But it didn't work. I don't know why. For the mainpage and other vHosts, Mod-Rewrite works. Quote Link to comment Share on other sites More sharing options...
madmax Posted January 29, 2008 Share Posted January 29, 2008 You have no path specified on the rewritelog so my guess either it is trying to open it in the wrong area to the one you are looking or cannot open due to insufficient rights in a "current" directory. Until you can enable logging and watch the logs you're poking around in the dark Quote Link to comment Share on other sites More sharing options...
Lumio Posted January 29, 2008 Author Share Posted January 29, 2008 I tried to create a writeable folder and wrote an absolute path. But it didn't work. RewriteEngine On RewriteLogLevel 9 RewriteLog /var/www/domain_dev.citrosaft.com/logs/rewrite.log RewriteCond %{HTTP_HOST} ^mubix\.citrosaft\.com$ [nc] RewriteRule (.*) http://dev\.citrosaft\.com/index.php/Mubix [L,R] Quote Link to comment Share on other sites More sharing options...
madmax Posted January 31, 2008 Share Posted January 31, 2008 Until you can enable logging and watch the logs you're poking around in the dark Did you enable logs and look at them? Not working in what way? Access/error logs still getting no hits? Sure? Have you tried removing the \. and changing to just . in the rewrite? RewriteEngine On RewriteLogLevel 9 RewriteLog /var/www/domain_dev.citrosaft.com/logs/rewrite.log RewriteCond %{HTTP_HOST} ^mubix\.citrosaft\.com$ [nc] RewriteRule (.*) http://dev.citrosaft.com/index.php/Mubix [L,R] Don't forget to disable rewrite logging after!!!!!! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.