Forum Moderators: phranque

Message Too Old, No Replies

301 redirect; rewriting the url

301 redirect; rewriting the url

         

jade233

10:11 pm on Jan 10, 2004 (gmt 0)

10+ Year Member



So I am able to do the 301 redirect in the .htaccess file. Although I am not able to rewrite the url.
this is what I have:

Options +FollowSymLinks
RewriteEngine on
RewriteRule mysite.com [mysite.com...] [R=301,L]

will redirect to the site, but wont change the url to www.mysite.com

thanks for all your help

jdMorgan

12:00 am on Jan 11, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jade233,

Welcome to WebmasterWorld [webmasterworld.com]!

This is probably what you need:


Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mysite\.com
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]

Ref: WebmasterWorld search [google.com]

Jim

jade233

1:24 am on Jan 11, 2004 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for the reply. Unfortunately, I did as suggested and again the redirect works yet
the url does not get rewritten.
Oddly enough even without the .htaccess file, when someone types in mysite.com, they do get redirected to www.mysite.com.
Could there perhaps be a hiddden .htaccess file on the server, or something that the web hosting has in place that perhaps over writes this!

genius36

4:25 pm on Jan 12, 2004 (gmt 0)

10+ Year Member



While you guys are on this subject. I have an .htacess file in my root/html directory that says this:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}!-s
RewriteRule ^page/(.*) /Merchant2/merchant.mvc?page=$1

RewriteCond %{HTTP_HOST} myorgsite\.org$ [NC]
RewriteCond %{REQUEST_URI}!^/myorgsite [NC]
RewriteRule ^(.*)$ /myorgsite%{REQUEST_URI} [L]

I noticed that Google index 96 pages a few weeks ago, and has come back since the second Rewrite was put in and only looked at one page. Could there be something wrong here? Do I need another way to use this rewrite? Also, I don't want Google to know that mysiteorg is part of mysite. Will it be able to realize that from this file?
I actually have several domains that are using the rewrite in this file, and I don't want them to show as connected to one another.
Thanks much for any input on this.

jdMorgan

7:51 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Genius36,

Introduction to mod_rewrite [webmasterworld.com]

Since your post is not directly-related to jade233's question, it really should be in a separate thread. But I don't see anything wrong with your code. Since you use internal redirects, search engines will be unaware of any rewrites. The only thing I saw was that your second rule could be either


RewriteRule ^(.*)$ /myorgsite/$1 [L]
- or -
RewriteRule .* /myorgsite%{REQUEST_URI} [L]

but this is just a "neatness" issue, and what you have should work OK. I suspect your site may be PR4 or below, and therefore, Google just doesn't visit often. Also, since they won't see any change due specifically to the addition of the rewrites, they won't feel the need to index often unless you change your actual page content.

If you have any doubts about your rewrites, test them using a browser and also using the server headers checker [webmasterworld.com] to make sure your server status response is correct - In your case, you expect a 200-OK and not a 301 or 302.

Jim

[edited by: jdMorgan at 8:01 pm (utc) on Jan. 12, 2004]

jdMorgan

8:01 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



jade233,

It's possible that your host has given you two top-level directories, one for each of your domain-name variants. So code inserted into your www-domain top-level directory may not affect requests that come through your non-www-domain directory. Look around using ftp or telnet, and see if you have two top-level directories.

Another possibility is that mod_rewrite is not supported by your host. In cases like yours, I suggest doing a simple test: Redirect from a URL that does not exist to one that you know exists, and check the results using your browser:


Options +FollowSymLinks
RewriteEngine on
RewriteRule ^nonexistent_file\.html$ /known_to_exist_file.html [R=310,L]

With this code in place, request "nonexistent_file.html" from your browser, and you should be redirected to the file that you know exists. Your browser should show the new URL. Flush your browser cache (Temporary Internet Files) before each test, to eliminate problems due to stale cached results. If it doesn't work, contact your hosting provider about mod_rewrite support.

Jim

genius36

8:13 pm on Jan 12, 2004 (gmt 0)

10+ Year Member



Thanks very much for the input, and sorry to interrupt.