Forum Moderators: phranque

Message Too Old, No Replies

rewrite dynamic to static on new domain

modrewrite 301 redirect dynamic static

         

babushka

2:17 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



I have a the following old site:

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!

jdMorgan

3:05 pm on Mar 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The "old" URL you posted looks incorrect, because there is no query string (GET parameters), and the syntax is invalid according to the HTTP/1.x protocol specifications. Please confirm whether either of the following match the old URL format:
xyz.oldsite.com/dir/?var1=1&var2=2
xyz.oldsite.com/dir/var1=1&var2=2

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]

Jim

babushka

4:32 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



Yes there is a ?, sorry I forgot to type it.

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?

g1smd

4:54 pm on Mar 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Make sure you properly cater for both www and non-www on both sites.

Clear your browser cache and test again.

babushka

5:08 pm on Mar 12, 2008 (gmt 0)

10+ Year Member



Thanks, tried that, no luck.

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

jdMorgan

11:48 pm on Mar 12, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You are guessing, and no matter what, you'll not find a solution by guessing.

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

babushka

4:16 am on Mar 13, 2008 (gmt 0)

10+ Year Member



Yes, guessing is about the best I can do for now. I did try some of my attempts on the old-domain but I thought there would be some solution for the new domain. Anyway, I will try this again on the old domain and see if it works. thanks.

babushka

4:50 pm on Mar 13, 2008 (gmt 0)

10+ Year Member



Ok, this is the .htaccess of the old site. (The oldsite is a subdomain subdomain.oldsite.com. That is where the .htaccess is).

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

g1smd

7:57 pm on Mar 13, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteCond applies only to the RewriteRule line immediately following it.

There's no need to escape the . in any of the redirect target URLs, but you do need it to be escaped in the source URL.

The RewriteRule does not "see" the leading "/" of the requested URL.

jdMorgan

3:35 am on Mar 14, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's frustrating because it's like race-car driving: There are only a very few 'correct' ways of doing it -- You have to get it exactly right to suit your goals. It's utterly unforgiving of the smallest errors. Typos or sloppy planning will cause a server wreck. On the other hand, it's very compact, fast, and powerful.

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]

In .htaccess, the path to the current directory (where the .htaccess file resides) is stripped from the path 'seen' by RewriteRule. Therefore, your first pattern would never match, because there is no leading slash on the URL-path examined by RewriteRule.

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