Mod Rewrite Help (Full Version)

All Forums >> [Web Development] >> Server Issues



Message


mbuna -> Mod Rewrite Help (4/12/2004 12:24:19)

Hello,

I have a site on my server that I want to redirect to a new domain.

My initial thoughts are that a rewrite rule would be best. However I'm not familiar with the syntax of this and my attempts so far have all failed.

At first I tried it in the .htaccess file of the site, and then I tried it in the <directory> directive of the server (httpd.conf file).

Can someone give me the mod rewrite statements to redirect all requests for objects in a site to a new domain?

IE:  anything that goes to http://domain1.com/ should now end up at http://domain2.com

EX:  http://domain1.com/index.php   -->  http://domain2.com/index.php
EX:  http://domain1.com/images/banners/test.jpg -->  http://domain2.com/images/banners/test.jpg


etc.

TIA!




ellipisces -> RE: Mod Rewrite Help (4/15/2004 15:23:53)

quote:

The RewriteBase directive explicitly sets the base URL for per-directory rewrites. As you will see below, RewriteRule can be used in per-directory config files (.htaccess). There it will act locally, i.e., the local directory prefix is stripped at this stage of processing and your rewriting rules act only on the remainder. At the end it is automatically added back to the path.

When a substitution occurs for a new URL, this module has to re-inject the URL into the server processing. To be able to do this it needs to know what the corresponding URL-prefix or URL-base is. By default this prefix is the corresponding filepath itself. But at most websites URLs are NOT directly related to physical filename paths, so this assumption will usually be wrong! There you have to use the RewriteBase directive to specify the correct URL-prefix.

Notice: If your webserver's URLs are not directly related to physical file paths, you have to use RewriteBase in every .htaccess files where you want to use RewriteRule directives.

Example:

Assume the following per-directory config file: #
# /abc/def/.htaccess -- per-dir config file for directory /abc/def
# Remember: /abc/def is the physical path of /xyz, i.e., the server
# has a 'Alias /xyz /abc/def' directive e.g.
#

RewriteEngine On

# let the server know that we were reached via /xyz and not
# via the physical path prefix /abc/def
RewriteBase /xyz

# now the rewriting rules
RewriteRule ^oldstuff\.html$ newstuff.html



I would test it in a folder one down from /WWW. It should go in .htaccess. be very careful of your paths. Most servers use the aliases...




Page: [1]

Valid CSS!




Forum Software © ASPPlayground.NET Advanced Edition 2.4.5 ANSI
0.046875