How below rewrite rule works

RewriteCond     %{REQUEST_URI}  ^/(mysite|yoursite)$
RewriteRule     ^(.*)           $1/     [R=301,L]

Open in new window


As per my understanding when you use R=301 then you need to provide a domain name (e.g. http://example.com) so that redirection can happen, what is the point in redirecting in the same server?
beer9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Steve BinkCommented:
Refer to http://httpd.apache.org/docs/current/rewrite/flags.html#flag_r

The [R] flag indicates that the redirection result should be sent to the client browser.  While you *can* provide a protocol, host, and port, they are optional - any missing items will be replaced with their counterparts from the current request.  In your example, the server will issue a 301 response to the client, which will make a second request to the same URL, only with a final '/' at the end.

The purpose of forcing an external redirect is generally to make the client aware of the new canonical URL for whatever resource they are requesting.  In this instance, forcing the '/' suffix may seem picky, but it could be important for CMS routing, or other application-level concerns.  Additionally, spiders (e.g., search engines) are supposed to honor the responses.  This rewrite is an inexpensive way, for example, to tell Google to correct a search result.

Without the [R] flag, this redirect would become a rewrite, meaning the server internally translates the requested URL to a new location without informing the client.  In the server's workflow, the request is still resubmitted as a new request, but there's no associated network traffic.  The only noticeable difference is that client will not know about the change (the address bar stays the same), and makes only one request.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
HTTP Protocol

From novice to tech pro — start learning today.