Apache Server configuration support - mod_rewrite usage in mixed OS environment

This is Interesting: Free IT Magazines  
Home > Archive > Apache Server configuration support > September 2007 > mod_rewrite usage in mixed OS environment





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author mod_rewrite usage in mixed OS environment
scott.kesler@gmail.com

2007-08-23, 1:22 am

If this is not the correct group for this question, please point me to
the appropriate place. I am new to Apache as well, so please forgive
stupid queries/questions.

My company currently has about 70 web sites that are served by Apache
running on Xserve (OS X 10.4+). (BTW - We have recently migrated off
of IIS 6 on W2K3) This web server connects to 4 CDA JBoss servers
(also Xserve) which connect to a Linux Oracle DB server. The web
server sees the website content via a mapped drive that resides on a
Windows 2K3 server.

The problem is that the 70 websites are changing domain names and
moving file locations quite often (due to different company
departments). This is a problem and we are working on the process to
fix it, but in the mean time we need a work around.

The mod_rewrite module seems like the solution, but from all of the
research I've done, the mod_rewrite module looks for a .htaccess
file. This file should be placed in the root of the web site. In our
case, the web site content is on a Windows server so we cannot place
the .htaccess file in any web site root directory because a filename
beginning with a '.' is not allowed in Windows.

My question is... can the .htaccess file be placed anywhere else? Can
a 'master' .htaccess file be created in /apache2/conf/ or something
similar?

The end result I'm looking for is:

Original URL:
http://www.foo.com/directory1/picture.jpg

Redirected to URL:
http://www.bar.com/directory1/picture.jpg

Any help is greatly appreciated.

Thanks,

Keslux
skesler at comcast.net

Davide Bianchi

2007-08-23, 7:22 am

On 2007-08-23, scott.kesler@gmail.com <scott.kesler@gmail.com> wrote:
> The mod_rewrite module seems like the solution, but from all of the
> research I've done, the mod_rewrite module looks for a .htaccess
> file.


You can use an .htaccess file or you can put your rewrite directly in
the configuration file, as you please.

Almost any directive that you can put in your configuration file can
also be put in an .htaccess file, see the documentation.

Davide

--
"Did you know God had a plan for you?"
"Does it involve a high-powered rifle and a belltower?"
HansH

2007-08-23, 7:22 am

<scott.kesler@gmail.com> schreef in bericht
news:1187832040.563738.23050@i38g2000prf.googlegroups.com...
> My company currently has about 70 web sites that are served by Apache
> running on Xserve (OS X 10.4+). (BTW - We have recently migrated off
> of IIS 6 on W2K3) This web server connects to 4 CDA JBoss servers
> (also Xserve) which connect to a Linux Oracle DB server. The web
> server sees the website content via a mapped drive that resides on a
> Windows 2K3 server.


> The mod_rewrite module seems like the solution, but from all of the
> research I've done, the mod_rewrite module looks for a .htaccess
> file.

To be a little more precise Apache looks for a .htaccess in each folder down
the path towards the file to be served. Any .htacces may contain directives
to be processed by mod_rewrite.

> This file should be placed in the root of the web site.

..htaccess can be placed in any folder

> In our case, the web site content is on a Windows server so we cannot
> place the .htaccess file in any web site root directory because a filename
> beginning with a '.' is not allowed in Windows.

Some GUI tools on Windows dislike an assumed nameless file
Just create the file using a CMDwindows en edit ...

> My question is... can the .htaccess file be placed anywhere else?
> Can a 'master' .htaccess file be created in /apache2/conf/

No ...

> or something similar?

Though you can use the same directives in the main config or per stie.

> The end result I'm looking for is:
> Original URL:
> http://www.foo.com/directory1/picture.jpg
> Redirected to URL:
> http://www.bar.com/directory1/picture.jpg

I don't like cros domain images ...

This is a full external redirect. More common use of mod_rewrite is to
'only' modifiing the mapping of an URL to a local file.

Assuming www.foo.com will share all images at www.bar.com, consider using an
alias directory1 ../bar/pictures/
in the config of www.foo
or use a junction point at Windows to show _without_copying_ the content of
../foo/directory1/ at ./bar/images1 too
http://support.microsoft.com/kb/205524


HansH


sean dreilinger

2007-09-13, 1:21 am

scott.kesler@gmail.com wrote:

if your internal file locations are shift around a lot, you can still offer a
persistent url space to your customers by implementing a reverse-proxy -
customers continue to use the same urls, and you proxy the internal content from
wherever it happens to be living. if the content moves [again and again], you
just change the proxy configuration to point at the new content source
behind-the-scenes -- that way the customers and web search engines that have
bookmarked your content will not need to change their urls.

whether you choose to reverse-proxy or redirect, here are three potential
solutions for you...

> My question is... can the .htaccess file be placed anywhere else? Can
> a 'master' .htaccess file be created in /apache2/conf/ or something
> similar?


you can use the apache Include directive to embed just about any file on the
system into your configuration at server (re)start:

http://httpd.apache.org/docs/2.2/mod/core.html#include

to embed a bunch of mod_rewrite rules (or other configuration directives that
accomplish the same redirects), you could have this in your httpd.conf:

Include /path/to/conf/rewrite_rules.txt

and, based on your example:

> The end result I'm looking for is:
> Original URL:
> http://www.foo.com/directory1/picture.jpg
> Redirected to URL:
> http://www.bar.com/directory1/picture.jpg


the /path/to/conf/rewrite_rules.txt file could include any of these three
approaches to mapping the old addresses to the new content location:

==== rewrite_rules.txt ===

### use mod_proxy to proxy the relocated content
### without exposing any changes to the end-user:

<ifModule mod_proxy.c>
ProxyRequests Off
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
ProxyPass /directory1 http://www.bar.com/directory1
ProxyPassReverse /directory1 http://www.bar.com/directory1
</IfModule>

### or...
### use apache mod_alias to handle the redirect

<ifModule mod_alias.c>
### redirect everything in /directory1 to directory1 on a different server:
RedirectMatch 301 ^/directory1/(.*) http://www.bar.com/directory1/$1
</ifModule>

### or...
### use mod_rewrite to handle the redirect

<ifModule mod_rewrite.c>
### redirect everything in /directory1 to directory1 on a different server:
RewriteEngine On
RewriteRule ^/directory1/(.*) http://www.bar.com/directory1/$1 [R=301,L]
</ifModule>


=== /end of rewrite_rules.txt ===

hth

--sean

--
sean dreilinger - http://durak.org/sean/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2009 webservertalk.com