
![]() |
nutballs
So im sure everyone has seen this cunk of htaccess code.
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L] how do I do this if I dont know what the domain is ![]() this does not work for obvious reasons if you understand mod-rewrite. RewriteCond %{HTTP_HOST} ^www. [NC] RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L] I know if have seen it somewhere, i just cant seem to find it. perkiset
"This does not work for obvious reasons if you understand mod_rewrite..." lost me there man - I think you're on the right track.
The deal is that by time you're at the .htaccess level, the virtual host has already been captured by Apache- meaning that it was already defined (ergo you'd know what it was...) - if you're asking about a true wildcard capture, then you'll need to code that into your .httpd.conf file, where you can get ahead of the dispatch portion of the web request... unless your httpd.conf file IS already wildcarded and the virtual host is pointing to (this) directory...I don't have time to check, but I think you're really close... I have stuff that is similar (albeit for a completely different purpose) in some of my httpd.conf files... but the truth is that there are some differences in behavior between httpd.conf and htaccess, so I could be leading you astray. The key is to collect and use a backreference from the condition, not the rule... RewriteCond %{HTTP_HOST} ^www.(.*) RewriteRule ^(.*)$ http://%1$1 [R=301,L] ...but if that pees the bed on you then do it right in PHP... (assuming you have all requests going to a dynamic handler...)(Didn't check this, you may need a / in the Rule between the % and $ reference) nutballs
duh, i think you pointed me in the right direction. I dont have a chance to check yet, but will post when i get it sorted.
nutballs
lol. actually that was the answer. thanks perk
perkiset
nw man... stumped me for a moment when you first posted and couldn't let it go LOL
nutballs
bah it needs a slash.
RewriteCond %{HTTP_HOST} ^www.(.*) RewriteRule ^(.*)$ http://%1/$1 [R=301,L] |

Thread Categories

![]() |
![]() |
Best of The Cache Home |
![]() |
![]() |
Search The Cache |
- Ajax
- Apache & mod_rewrite
- BlackHat SEO & Web Stuff
- C/++/#, Pascal etc.
- Database Stuff
- General & Non-Technical Discussion
- General programming, learning to code
- Javascript Discussions & Code
- Linux Related
- Mac, iPhone & OS-X Stuff
- Miscellaneous
- MS Windows Related
- PERL & Python Related
- PHP: Questions & Discussion
- PHP: Techniques, Classes & Examples
- Regular Expressions
- Uncategorized Threads