For Programmers: Free Programming Magazines  


Home > Archive > PHP Programming > October 2007 > mod_rewrite rules for live site









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 rules for live site
dennis.sprengers@gmail.com

2007-10-27, 7:01 pm

* I'm trying to work out some rewrite rules that should do the
following:

case 1: a request to mysite.com:
rewrite http://www.mysite.com/files/sheets.ppt
to http://www.mysite.com/sites/default/files/sheets.ppt

case 1 - n: a request to othersite.com:
rewrite http://www.othersite.com/files/sheets.ppt
to http://www.othersite.com/sites/othe...iles/sheets.ppt

So, if a request comes in to mysite.com, /files/-urls need to be
rewritten do /sites/default/files/sheets/ppt, since mysite is the
default website on the server. Surfing to a file on any other website
that is hosted on the server, needs to be rewritten to /sites/
<name_of_site>/files/sheets.ppt

Sheets.ppt is of course just an example of a file file.

* I first tested my CMS (for which I need these rules) on my own
little server @home, and found these rules to be working OK after
spending hours on forums on apache and mod_rewrite:

# http://localhost/mysite/files/* > /mysite/sites/default/files/*
RewriteCond %{REQUEST_URI}-default ^/mysite/.+-(default)$ [NC,OR]
# http://loclahost/<othersite>/files/* > /<othersite>/sites/
<othersite>/files/*
RewriteCond %{REQUEST_URI}-default ^(.+)(default)$ [NC,OR]

But now I have no clue on where to begin anymore, since it has been a
long time I researched mod_rewrite. Could somebody help me out? Any
help is appreciated :-)

ZeldorBlat

2007-10-27, 7:01 pm

On Oct 27, 1:22 pm, dennis.spreng...@gmail.com wrote:
> * I'm trying to work out some rewrite rules that should do the
> following:
>
> case 1: a request to mysite.com:
> rewritehttp://www.mysite.com/files/sheets.ppt
> tohttp://www.mysite.com/sites/default/files/sheets.ppt
>
> case 1 - n: a request to othersite.com:
> rewritehttp://www.othersite.com/files/sheets.ppt
> tohttp://www.othersite.com/sites/othersite/files/sheets.ppt
>
> So, if a request comes in to mysite.com, /files/-urls need to be
> rewritten do /sites/default/files/sheets/ppt, since mysite is the
> default website on the server. Surfing to a file on any other website
> that is hosted on the server, needs to be rewritten to /sites/
> <name_of_site>/files/sheets.ppt
>
> Sheets.ppt is of course just an example of a file file.
>
> * I first tested my CMS (for which I need these rules) on my own
> little server @home, and found these rules to be working OK after
> spending hours on forums on apache and mod_rewrite:
>
> #http://localhost/mysite/files/*> /mysite/sites/default/files/*
> RewriteCond %{REQUEST_URI}-default ^/mysite/.+-(default)$ [NC,OR]
> #http://loclahost/<othersite>/files/* > /<othersite>/sites/
> <othersite>/files/*
> RewriteCond %{REQUEST_URI}-default ^(.+)(default)$ [NC,OR]
>
> But now I have no clue on where to begin anymore, since it has been a
> long time I researched mod_rewrite. Could somebody help me out? Any
> help is appreciated :-)


You're making it harder than you need to. Just use an alias:

Alias /files <path to the webroot>/sites/default/files

dennis.sprengers@gmail.com

2007-10-27, 7:01 pm

> You're making it harder than you need to. Just use an alias:
>
> Alias /files <path to the webroot>/sites/default/files


I would really like it to work with mod_rewrite rules in .htaccess, so
that I don't have to create a new alias for every website I might add
in the future. So if you understand mod_rewrite, please throw me a
bone here :-)

Jerry Stuckle

2007-10-27, 7:01 pm

dennis.sprengers@gmail.com wrote:
> * I'm trying to work out some rewrite rules that should do the
> following:
>
> case 1: a request to mysite.com:
> rewrite http://www.mysite.com/files/sheets.ppt
> to http://www.mysite.com/sites/default/files/sheets.ppt
>
> case 1 - n: a request to othersite.com:
> rewrite http://www.othersite.com/files/sheets.ppt
> to http://www.othersite.com/sites/othe...iles/sheets.ppt
>
> So, if a request comes in to mysite.com, /files/-urls need to be
> rewritten do /sites/default/files/sheets/ppt, since mysite is the
> default website on the server. Surfing to a file on any other website
> that is hosted on the server, needs to be rewritten to /sites/
> <name_of_site>/files/sheets.ppt
>
> Sheets.ppt is of course just an example of a file file.
>
> * I first tested my CMS (for which I need these rules) on my own
> little server @home, and found these rules to be working OK after
> spending hours on forums on apache and mod_rewrite:
>
> # http://localhost/mysite/files/* > /mysite/sites/default/files/*
> RewriteCond %{REQUEST_URI}-default ^/mysite/.+-(default)$ [NC,OR]
> # http://loclahost/<othersite>/files/* > /<othersite>/sites/
> <othersite>/files/*
> RewriteCond %{REQUEST_URI}-default ^(.+)(default)$ [NC,OR]
>
> But now I have no clue on where to begin anymore, since it has been a
> long time I researched mod_rewrite. Could somebody help me out? Any
> help is appreciated :-)
>
>


And your PHP question is?

Try an appropriate newsgroup - such as alt.apache.configuration.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com