Mod_rewrite and redirect with subdomain

Hello,

simply we tried use .htaccess redirect dynamic URL to virtual sub domain with same dynamic URL with this code

RewriteCond %{HTTP_HOST} ^mysite\.net [NC]
RewriteCond %{QUERY_STRING} ^link=(.+)$
RewriteRule ^news\.php$ http://news.mysite.net/news.php?link=%1 [L,R=301]

http://mysite.net/news.php?link=97 to http://news.mysite.net/news.php?link=97

need help with 3 things

1-.htaccess code redirect 301 all old links http://mysite.net/news.php?link=97 to http://news.mysite.net/97.html
2-redirect 301 all old links http://mysite.net/news.php?link=97 to http://news.mysite.net/97.html
3-virtual sub domain of http://news.mysite.net has its page not get index page as it happen now

Thanks

meno,

You might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, tYou might benefit from reading the mod_rewrite tutorial linked in my signature as it contains explanations and sample code. It’s helped may members and should help you, too.

Now, the problem may be with how your subdomain is setup. Is it’s DocumentRoot the news subdirectory of mysite.net? Is the DirectoryIndex of the news subdomain news.php? These answers are critical to answering your question.

Caution: Redirect is a mod_alias directive while redirect is what mod_rewrite is capable of doing to a request. Please be sure to specify whether you’re asking a mod_alias question or a mod_rewrite question (because I don’t believe mod_alias can look at a query string, you need mod_rewrite).

Regards,

DK

news sub domain is not founded
but it’s virtual sub domain by Mod_Rewrite
this is answer of your question

meno,

If the subdomain is “virtual,” then it’s not available to be linked to because it doesn’t exist. For your redirection to work, you must establish the subdomain.

Regards,

DK

Now we use virtual subdomain and can do this

http://mysite.net/news.php?link=97 to http://news.mysite.net/news.php?link=97

how we can do (without subdomain linked)

1-.htaccess code redirect 301 all old links http://mysite.net/news.php?link=97 to http://news.mysite.net/97.html
2-redirect 301 all old links http://mysite.net/news.php?link=97 to http://news.mysite.net/97.html

thanks for replies

meno,

Every subdomain is registered and is, in effect, another domain on the Internet. The only way to handle a request for a subdomain is to have it registered with your DNS (domain name server). If you do not do this, any redirection to unregistered_subdomain.example.com will fail to find the host. If it fails to find a host, it cannot be handled by your host (or by mod_rewrite).

I suspect that you DO have news setup as a subdomain so I must repeat my question: What is the physical location of the DocumentRoot of the news subdomain?

Regards,

DK