Forum Moderators: phranque

Message Too Old, No Replies

rewrite issue

         

speedyone

8:34 pm on Mar 10, 2009 (gmt 0)

10+ Year Member



I seem to ba having an issue maybe you guys can help with. I am doing a rewrite rule and have it do the following

RewriteCond %{HTTP_HOST} ^my\.newsite\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/$.*$ [NC]
RewriteCond %{REQUEST_URI} !^/_.*$ [NC]
RewriteCond %{REQUEST_URI} !^/folder1.*$ [NC]
RewriteCond %{REQUEST_URI} !^/folder2.*$ [NC]
RewriteCond %{REQUEST_URI} !^/folder3.*$ [NC]
RewriteCond %{REQUEST_URI} !^/folder4.*$ [NC]
RewriteCond %{REQUEST_URI} !^/folder5.*$ [NC]
RewriteRule (.*)$ [old.site.net$1...] [R,L]

I am moving my site to a new one. However I have only a few things moved over. So when you go to the old domain I want it to redirect all to the old.site.net. However I created folders for the things that are already moved. These exceptions work but I also need to exclude

/?locale=en_US

when I add the query_string it breaks the /root redirect. Any help would be great.

g1smd

8:38 pm on Mar 10, 2009 (gmt 0)

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



You need to look at QUERY_STRING for that.

There are two $ symbols in one condition, that's likely an error.

You can lose the .*$ from the end of most of those conditions.

Be aware that R gives a 302 redirect. You'll need R=301 instead.

speedyone

8:43 pm on Mar 10, 2009 (gmt 0)

10+ Year Member



So something like:

RewriteCond %{QUERY_STRING} !locale=[NC]

But this seems to not catch it.

jdMorgan

11:42 pm on Mar 10, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to be very, very careful with mod_rewrite. Your line is missing a space, and one single typo in mod_rewrite or in the regular-expressions patterns that it uses can take your server down immediately -- if you are lucky. If you're not lucky, that typo may sit there for months, slowly destroying your search engine rankings.

RewriteCond %{HTTP_HOST} ^my\.newsite\.com [NC]
RewriteCond %{QUERY_STRING} !locale=en_US [NC]
RewriteCond %{REQUEST_URI} !^/$
RewriteCond %{REQUEST_URI} !^/_
RewriteCond %{REQUEST_URI} !^/folder1/ [NC]
RewriteCond %{REQUEST_URI} !^/folder2/ [NC]
RewriteCond %{REQUEST_URI} !^/folder3/ [NC]
RewriteCond %{REQUEST_URI} !^/folder4/ [NC]
RewriteCond %{REQUEST_URI} !^/folder5/ [NC]
RewriteRule ^/(.*) http://old.site.net/$1 [R=302,L]

Based on your original code, I assumed this code is going into a server config file, and not into a .htaccess file.

You'd actually be far better off redirecting from the old site to the new with a 301 redirect instead of redirecting from the new site to the old with a 302. Doing so will confuse the search engines, and may delay their recognition of your new site when/as you remove these 302 redirects.

Jim

[edited by: jdMorgan at 11:43 pm (utc) on Mar. 10, 2009]

g1smd

11:54 pm on Mar 10, 2009 (gmt 0)

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



I am guessing they maybe wanted a "rewrite from new URLs to old content", based on a mis-understanding as to how rewrites/redirects work.

speedyone

12:11 am on Mar 11, 2009 (gmt 0)

10+ Year Member



yeah.. I am aware of all that. This is now they want to do it. The old servers are windows and I am trying to get them to move the site to apache. the redirects are lame in windows and we can't do some of the things we want. So we end up with what we have now. :o(

thanks for the help

speedyone

12:20 am on Mar 11, 2009 (gmt 0)

10+ Year Member



so this is still redirecting the /?locale=en_US so frustrating.

jdMorgan

12:49 am on Mar 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Is the query string spelled correctly? Did you restart the server after changing the code? Did you completely flush your browser cache after changing the code and before testing?

There's no magic to this... Something just isn't correctly-coded, or it's a correct code implementation of an incorrect requirement.

Jim

speedyone

5:21 pm on Mar 11, 2009 (gmt 0)

10+ Year Member



yeah i am doing all that.

jdMorgan

7:06 pm on Mar 11, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well then it is likely that the patterns or the logic in the code do not exactly match the request parameters or the desired goal, respectively. Whatever it is, it won't be obvious to us, so you're going to have to look very hard at what that code says and does, check every detail, and experiment if needed.

As it stands, the rule will not execute if the query string contains "locale=en_US" regardless of upper/lowercase, and regardless of the requested URL to which that query string is appended.

Jim