arvind Posted September 29, 2003 Posted September 29, 2003 have my blog setup on a subdomain that is accessible by going to http://blog.domain.com, but not http://www.blog.domain.com. However, I would like for users to still be able to type http://www.blog.domain.com and get the blog instead of the friendly 404 page. I was thinking that the best way to do this would be to use mod_rewrite. I searched around the forums and found some threads with code. I modified one snippet, but it didn't work when testing it. >RewriteEngine On RewriteCond %{HTTP_HOST} !^blog\.domain\.com RewriteRule ^(.*)$ http://blog.domain.com/$1 [L,R] must be something that I messed up with my code. Does anyone know how I could improve that code or have code that I could use? Any help would be greatly appreciated. Quote
surefire Posted September 30, 2003 Posted September 30, 2003 First, I read somewhere that subdomains have to be typed in without the www... and I never verified that for certain. But up until now, that's what I've assumed. You asked about mod rewrite. Before I came to TCH, I wanted to use Apache Force Type but my old host ran windows or it wouldn't work for some reason so I worked my way through with mod rewrite and successfully did it. It wasn't easy and that's my only experience with mod rewrite. I found this RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC]RewriteCond %{HTTP_HOST} !^$RewriteCond %{SERVER_PORT} !^80$ RewriteRule ^/(.*) http://fully.qualified.domain.name:%{SERVE...R_PORT}/$1 [L,R] RewriteCond %{HTTP_HOST} !^fully\.qualified\.domain\.name [NC] RewriteCond %{HTTP_HOST} !^$ RewriteRule ^/(.*) http://fully.qualified.domain.name/$1 [L,R] Here http://httpd.apache.org/docs/misc/rewriteguide.html So you might want to check that out. I tried to Google your question and didn't come up with much. Sorry. Quote
arvind Posted September 30, 2003 Author Posted September 30, 2003 OK that completely confused me Ummm without all the jargon is there some easy way I can get people who type http://www.blog.**** to be redirected to http://blog.**** ? Quote
surefire Posted September 30, 2003 Posted September 30, 2003 Found this in Google... this looks like the answer you are looking for ht*p://isp-lists.isp-planet.com/isp-webhosting/0203/msg00551.html I wrote the above url so there wouldn't be a link... I think you know to replace the * with a t. I'm sorry the Apache Mod Rewrite info was confusing... but this stuff isn't easy. Please be aware that if you start giving the server instructions to modify your urls without really knowing what's going on, then you run the risk of something going haywire in a big way. Quote
arvind Posted September 30, 2003 Author Posted September 30, 2003 thanks rite i'll have a look at the link . Yeah I put that code (form my first post) into my htaccess and everything got screwed. My whole subdomain crashed but was easily fixed by removing that line ! Quote
arvind Posted September 30, 2003 Author Posted September 30, 2003 Rite had a look at the code on that page. Wow i'm more confused. SHould I attempt this what does that code do ? Quote
surefire Posted September 30, 2003 Posted September 30, 2003 (edited) >RewriteEngine on ## Ignore www.**** and **** RewriteCond %{HTTP_HOST} !^www\.yourdomain\.com [NC] RewriteCond %{HTTP_HOST} !^yourdomain\.com [NC] ## A directory with the name of the subdomain must exist RewriteCond %{DOCUMENT_ROOT}/%1 -d ## Add the requested hostname to the URI ## [C] means that the next Rewrite Rules uses this RewriteRule ^(.+) %{HTTP_HOST}/$1 [C] ## Translate abc.****/foo to ****/abc/foo RewriteRule ^([a-z0-9A-Z]+)\.yourdomain\.com/?(.*)$http://www.******/$1/$2 [L] create a text file name it whatever you want Add the above code to it replace 'yourdomain' with your domain (leave out www and dot whatever) save the file ftp the file to your server in your public_html directory rename the file .htaccess My whole subdomain crashed but was easily fixed by removing that line ! SHould I attempt this Seems like you've seen what can happen and you survived. It probably wouldn't be a bad idea to back up your site... database and all. But that's just good policy whenever making a major change site wide. what does that code do ? Dunno. Didn't write it. Edited September 30, 2003 by surefire Quote
arvind Posted October 2, 2003 Author Posted October 2, 2003 it looks like this code just redirects abc.**** to ****/abc look at this line ## Translate abc.****/foo to ****/abc/foo sorry but that's not what i wanted. I don't want to attempt something before I'm sure that I really want to do it because if that's what the code does then I'm not putting it into my htaccess sorry for the trouble ! Quote
vendlus Posted October 2, 2003 Posted October 2, 2003 I'm not sure about this, but I am not sure what you want can be done. Currently, www already is a subdomain that points to your public_html folder. So what you're looking for is a way to change where a subdomain points to, correct? (You want it to point to '/public_html/blog' instead of '/public_html'.) Anyone know how the server knows to send www to public_html?? I would think that is where the change would need to be made (or at least, that's what htaccess would have to override, if possible). *edit* after reading the link surefire gave, it does indeed claim to do what you want. I'm not entirely sure what it's doing either, but that is what it claims to do. Quote
a__kc Posted October 28, 2003 Posted October 28, 2003 have my blog setup on a subdomain that is accessible by going to http://blog.domain.com, but not http://www.blog.domain.com. However, I would like for users to still be able to type http://www.blog.domain.com and get the blog instead of the friendly 404 page. Honestly, www.subdomain.domain.org looks so ugly, I am inclined to show the user the friendly 404 (along with a site map and search box) Another thing is, rewrite rules make use of regular expressions, and bad expressions can slow down the server and delay page display. Quote
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.