Forum Moderators: phranque

Message Too Old, No Replies

Need Help with mod_rewrite - domain.com to www.domain.com

I used an example.. but something is wrong

         

sdani

2:21 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Purpose was to redirect domain.com to www.domain.com. I used the mod_rewrite code provided by Jim in this thread (http://www.webmasterworld.com/forum23/1600.htm) and inserted it in my existing htaccess file. My new htaccess looks like this:
************************************

RewriteEngine on
Options +FollowSymlinks
RewriteBase /
RewriteRule ^(.*)CATALOG/(.*)$ $1/CATALOG.php?item=$2
RewriteRule ^(.*)catalog/(.*)$ $1/CATALOG.php?item=$2
RewriteRule UnknownError UnknownError.php
RewriteCond %{HTTP_HOST}!^www\.widget\.com
RewriteRule .* [widget.com...] [R=301,L]
IndexIgnore *
ErrorDocument 400 /error.php?code=400
ErrorDocument 401 /error.php?code=401
ErrorDocument 403 /error.php?code=403
ErrorDocument 404 /error.php?code=404
ErrorDocument 405 /error.php?code=405
ErrorDocument 406 /error.php?code=406
ErrorDocument 412 /error.php?code=412
ErrorDocument 414 /error.php?code=414
ErrorDocument 500 /error.php?code=500
ErrorDocument 501 /error.php?code=501

DirectoryIndex index.php

************************************

Now if I type domain.com, it is redirect to [domain.com...] note TWO // at the end of the URL. Similarly, if I type [domain.com...] it also becomes [domain.com...] (again note two //).

Can someone suggest what am I doing wrong?

Two additional question:
1. What does [R=301,L] mean?
2. I have seen [NC] in some examples, but I am not using it because it was not mentioned in jim's example.. should I be using it?

Thanks
SD

jdMorgan

4:47 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



sdani,

%{REQUEST_URI} will contain a leading slash. Since you also have a trailing slash in your substitution URL, you end up with two -- one from your substitution followed immediately by another in %{REQUEST_URI}.

For the other questions, I would suggest taking a look at the documentation.

Apache mod_rewrite documentation [httpd.apache.org]
Apache URL Rewriting Guide [httpd.apache.org]
Regular Expressions Tutorial [etext.lib.virginia.edu]

Jim

sdani

7:10 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Jim,

Thanks for the pointers. So are you suggesting that I cahnge it to read like this?

RewriteRule .* [widget.com%{REQUEST_URI}...] [R=301,L]

I have copied the exact syntax what you had posted in the original thread, then why is this extra "/" is not a problem for anyone else? Can you please suggest me what is unique in my htaccess setting.

Also, I read the three links you mentioned, I stilll could not find what is "L" in [R=301,L].

Thanks a lot!
SD

coopster

7:25 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Do a search for "trailing slash" in the URL Rewriting guide. It's mentioned quite a few times in there and you'll understand it better once you've read up on it.

I still could not find what is "L" in [R=301,L]

In the mod_rewrite documentation, under the RewriteRule [httpd.apache.org] area, you will find the last rule flag and it's description.

sdani

7:28 pm on Jul 5, 2004 (gmt 0)

10+ Year Member



Thanks coopster:

Truly appreciate your inputs.

Regards
SD

coopster

8:01 pm on Jul 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



You are quite welcome. Apache's mod_dir [httpd.apache.org] module also has a good explanation for you.