.htaccess - Help with variables in htaccess redirects -


i want this, redirect:

http://anysubdomain(wildcard).mydomain.com/

to

anysubdomain(wildcard).mydomain.com/page2.php

i tried this:

  rewritecond %{http_host} ^(.*)\.mydomain.com$ [or]   rewriterule ^/?$ "http\:\/\/$1\.mydomain\.com\/page2\.php" [r=301,l] 

but not work, rewritecond part works well, because, subdomain redirected.

but reaches: " .mydomain.com/page2.php"

can me? thanks!

there's few things wrong rewrite:

  1. the [or] making apply everything
  2. you don't need escape many chars on rule.
  3. need pass through hostname variable using %1
  4. it'll create infinite loop, it'll try redirecting page2.php itself.

this should it:

rewritecond %{request_filename} !.*page2.php$ rewritecond %{http_host} ^(.*)\.mydomain.com$ rewriterule ^(.*)$ http://%1.mydomain.com/page2.php [r=301,l] 

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -