Forum Moderators: phranque
xyz.oldsite.com/dir/var1=1&var2=2
I need to redirect that permantely to the new site:
newsite.com/newpage.php
The newpage.php does not include any of the values from the vars above.
On the old site I have redirected the whole site as follows:
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ [newsite.com...] [R=301,L]
On the new site I have tried:
#RewriteCond %{QUERY_STRING} ^var1=1&var2=2$
#RewriteRule ^newpage\.php$ /dir/var1=1&var2=2 [R=301,L]
But that doesn't work. It just goes to the home page with the get string attached.
Any help?
Also the rest of the new site htaccess reads like this:
# Redirect direct client requests for /index.php [R=301,L] or /index.shtml in
# any subdirectory back to www.example.com/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(.+/)?index\.(php¦html)$ [newsite.com...] [R=301,L]
#
# Redirect direct client requests for /subdir/ back to www.example.com/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^oldsitedir(/(.*))?$ [newsite.com...] [R=301,L]
#
# Redirect direct client requests for /subdir/ back to www.example.com/
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^newsitedir(/(.*))?$ [newsite.com$1...] [R=301,L]
#
# Rewrite Web root directory requests to /subdir
RewriteRule !^newsitedir(/.*)?$ /newsitedir%{REQUEST_URI} [QSA,L]
#
That all works fine. I tried putting the actual page redirect both above and below, but I can't get it to work.
I've tried lookint at httpheaders in firefox, but I just dont get how to debug this issue. Is there some other log file on the server that may help me? I am new to apache and linux.
Thanks!
I'll assume the first line is correct for now.
If you want to clear the query string (GET variable), add a question mark to the end of the substitution URL; This question mark is a "token" and will not "show" in the redirected URL:
RewriteCond %{QUERY_STRING} ^var1=1&var2=2$
RewriteRule ^dir/$ http://newsite.com/newpage\.php? [R=301,L]
I have tried that, and it doesn't work. It redirects to:
[newsite.com...]
I want it to redirect to:
[newsite.com...]
Here what Iput in .httacces of newsite:
RewriteCond %{QUERY_STRING} ^var1=1&var2=2$
RewriteRule ^olddir/$ [newsite.com...] [R=301,L]
Any ideas?
I tried putting the full url of the old site:
RewriteCond %{QUERY_STRING} ^var1=1&var2=2$
RewriteRule ^old-subdomain.olddomain.com/oldir/$ [newsite.com...] [R=301,L]
And I tried with www:
RewriteCond %{QUERY_STRING} ^var1=1&var2=2$
RewriteRule ^old-subdomain.olddomain.com/oldir/$ [newsite.com...] [R=301,L]
But they all redirect to the homepage and include the query
string. :(
The domain name must not be part of the RewriteRule pattern; That will never work, since RewriteRule 'sees' only the URL-path localized to the directory in which it resides.
The code I posted above is correct for the problem as you described it. Be sure that your description was correct. The code must be placed in old-domain.com/.htaccess if /dir is located at old-domain.com/dir
Jim
The page that needs to be redirected is:
subdomain.oldsite.com/subdir/index.php?var1=1&var2=2
RewriteCond %{QUERY_STRING} ^var1=1&var2=2$
RewriteRule ^/subdir/index.php$ [newsite.com...] [R=301,L]
RewriteRule ^(.*)$ [newsite.com...] [R=301,L]
It acts like it ignores the first two lines. Everything gets redirected to the home page and the query string is still attached. Is there some log file or something I can look at to find out what is going on?
I don't know why I find this whole rewrite stuff frustrating. :(
One thing that helps a lot is to include meaningful comments. It helps us, and it will help you -- now or later.
# Redirect requests for /subdir/index.php?var1=1&var2=2 to newsite.com/newpage.php
RewriteCond %{QUERY_STRING} ^var1=1&var2=2$
RewriteRule [b]^s[/b]ubdir/index\.php$ http://newsite.com/newpage.php? [R=301,L]
#
# Redirect all other URL-path requests to same URL-path on newsite.com
RewriteRule (.*) http://newsite.com/$1 [R=301,L]
This code should work in oldsite.com/.htaccess. It won't work in /oldsite.com/subdir/.htaccess, unless you remove "subdir/" from the RewriteRule pattern.
Jim