views:

2466

answers:

3

I have a site that has been up for some time. I had a blog on a subdomain for some time. I have decided to do away with the main site and just support the blog subdomain.

I have a redirect setup for this, but it carries all the extra parameters through to the blog which results in a file not found page appearing. I just want the redirect to go to the index page without parameters.

What I currently have in my .htaccess file is this

RewriteCond %{HTTP_HOST} ^.*$
RewriteRule ^/?(.*)$ "http\:\/\/blog\.foo\.org\/index\.php" [R=301,L]

When I get a request to

http://www.foo.org/foo/foo/?module=foo

it redirects to

http://blog.foo.org/foo/foo/index.php?module=foo

I want it to redirect to http://blog.foo.org/index.php

+1  A: 
RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www\.)?foo\.org$ [NC]
RewriteRule ^ http://blog.foo.org/ [R=301,L]
Mark Hurd
A: 

You have to specify the query in the replacement to override the original:

RewriteCond %{HTTP_HOST} !^blog\.example\.org$ [NC]
RewriteRule ^ http://blog.example.org/index.php? [R=301,L]
Gumbo
Makes sense. Tried it and it works like a champ.
A: 

I have One issue, please help me. My issue is I have url subdomain.mydomain.com and want to redirect them mydomin.com/folder1/index.php?user=subdomain. but I don't want to change URL in addressbar so in addressbar the url should be subdomain.mydomain.com. What i have to do? My .htaccess code is

RewriteCond %{HTTP_HOST} !^www\.mydomain.com [NC]
RewriteCond %{HTTP_HOST} ([^.]+)\.mydomain.com [NC]
RewriteRule ^(.*)$ http://mydomain.com/folder1/index.php?user=%1 [L]

It redirect correctly, But Unfortunately, it affects the addressbar, so it's useless for me. Please help me. What I have to do? Thanks in advance.

vijay
You probably will need a different approach, since a redirect redirects the browser, and therefore the browser will show the new url. That being said, better ask this as a new question, not here in an old thread. More people would see it and try to help you. The "Ask Question" button is in the top right of the page...
sth