So im sure everyone has seen this cunk of htaccess code.

RewriteCond %{HTTP_HOST} ^$ [NC]
RewriteRule ^(.*)$$1 [R=301,L]

how do I do this if I dont know what the domain isApplause
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.


"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


  - 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


 ... (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)


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.


lol. actually that was the answer. thanks perk


nw man... stumped me for a moment when you first posted and couldn't let it go LOL


bah it needs a slash.

RewriteCond      %{HTTP_HOST} ^www.(.*)
RewriteRule      ^(.*)$  http://%1/$1  [R=301,L]

Perkiset's Place Home   Politics @ Perkiset's