Closed Thread Icon

Topic awaiting preservation: mod_rewrite .htaccess regexp help... Pages that link to <a href="https://ozoneasylum.com/backlink?for=23511" title="Pages that link to Topic awaiting preservation: mod_rewrite .htaccess regexp help..." rel="nofollow" >Topic awaiting preservation: mod_rewrite .htaccess regexp help...\

 
Author Thread
smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-01-2004 20:48

Hi Guys, it's been a while...

Basically I have a mod_rewrite masked redirect set up that works fine for me:

code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(ww+\.)?scrwd\.com

RewriteCond %{REQUEST_URI} !/directory1/

RewriteRule ^(.*)$ /directory1/$1 [L]



However this works simple by shifteing the whole url directory structure - so basically what would have been www.scrwd.com now looks the same but actually points to www.scrwd.com/directory1. And www.scrwd.com/directory2 is really pointing to www.scrwd.com/directory1/directory2.

but I want to make a front controller php script so basically I want www.scrwd.com/anything/I/like/here to always point to the same php script in the root directory. Then in that script I will be exploding the /anything/I/like/here bit and using it to return the correct dynamic page.

I'm thinking it should lokke something like this:

code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(ww+\.)?scrwd\.com.* <----match any character zero or more times.

RewriteCond %{REQUEST_URI} !/directory1/

RewriteRule ^(.*)$ /directory1/$1 [L] <----or maybe by removing the $1 ?



I don't really know what I'm doing here, it confuses me, basically I want any url that starts with ^(ww+\.)?scrwd\.com to be invisbly sent to the same php script (or directory1 which contains it as teh default index already)

Any hep would be appreciated.

Thanks guys,

Jon

SCRWD//MULTIMEDIA PORTAL

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 10-01-2004 21:36

I think this will do the trick. Don't really have time to test it right now, but if you try it and it doesn't work, post here again. We'll work it out

code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(ww+\.)?scrwd\.com <----the '.*' is superfluous.
RewriteCond %{REQUEST_URI} !/script.php/
RewriteRule ^(.*)$ /script.php/$1 [L]



-- not necessarily stoned... just beautiful.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-01-2004 21:51

here's what the asylum (grail) uses

code:
RewriteRule ^$ /page.php
RewriteRule ^([0-9]+) /page.php?g_mode=show&id=$1&%{QUERY_STRING} [L]
RewriteRule ^(show|admin|preserve|create|manage|special|user)/([0-9a-zA-Z]+) /page.php?g_mode=$1&id=$2&%{QUERY_STRING} [L]
RewriteRule ^([a-zA-z]{1}[[a-zA-z\ 0-9]*)$ /page.php?g_mode=special&id=$1&%{QUERY_STRING} [L]



so long,
->Tyberius Prime

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-01-2004 23:02

Ok thanks guys,

I'm still having trouble though.

This works except I need to add an 'if not...' in there. How do I do 'if / else' statements in .htaccess?

SCRWD//MULTIMEDIA PORTAL

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 10-01-2004 23:16

smonkey:

quote:
This works except I need to add an 'if not...' in there



What kind of if not? The code I gave you has an if not in it. The third line says:

code:
RewriteCond %{REQUEST_URI} !/script.php/


That means if the requested uri does not contain the string /script.php/

What is the if not you want to test for?

-- not necessarily stoned... just beautiful.


(Edited by hyperbole on 10-01-2004 23:17)

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-01-2004 23:51

ok basically this is what I'm doing,

I have one hosting account with 5 different domains all assigned to it, they all point to the root directory.

I wanted to give the appearance that each site is infact independent, that is where the mod_rewrite comes in and it works fine.

However I now want to make a front controller one of the sites within my single hosting account.

It works fine if I remove the $1 from the rewrite rule (see first code in first post)

However it fails in terms of images, because any requests for images are also redirected to the single front controller - I'd rather not have to use the front controller for serving images too, so I want some way of 'excluding' any image requests from from being redirected. But they still need to be partially redirected because the image folder is within the 'subsite' root folder.

The structure looks like this (fingers crossed this works ok)

code:
www.domain1.com |                                        |---> root/directory1
| | '---> root/directory1/images
| |
www.domain2.com | |---> root/directory2
| | '---> root/directory2/images
| |
www.domain3.com |---> my hosting /root ---> .htaccess ---|---> root/directory3
| | '---> root/directory3/images
| |
www.domain4.com | |---> root/directory4
| | '---> root/directory4/images
| |
www.domain5.com | |---> root/directory5
'---> root/directory5/images



SCRWD//MULTIMEDIA PORTAL

(Edited by smonkey on 10-01-2004 23:53)

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 10-02-2004 04:44

OK, sorry it has taken me so long to answer you on this. My wife called me to dinner about the time I was getting ready to answer you.

If the reason you are creating the .php file is to direct the user to the appropriate directory, it seems to me you can do all that with the .htaccess file.

Try the following:

code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain1\.com
RewriteCond %{REQUEST_URI} !/directory1/
RewriteRule ^(.*)$ /directory1/$1 [L]
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain2\.com
RewriteCond %{REQUEST_URI} !/directory2/
RewriteRule ^(.*)$ /directory2/$1 [L]
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain3\.com
RewriteCond %{REQUEST_URI} !/directory3/
RewriteRule ^(.*)$ /directory3/$1 [L]
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain4\.com
RewriteCond %{REQUEST_URI} !/directory4/
RewriteRule ^(.*)$ /directory4/$1 [L]
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain5\.com
RewriteCond %{REQUEST_URI} !/directory5/
RewriteRule ^(.*)$ /directory5/$1 [L]



That should allow you to access each of the directories without having to use the .php file. Of course, there may be another reason you want to use the .php file, but, you haven't said that so try this .htaccess file.

-- not necessarily stoned... just beautiful.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-02-2004 14:58

Hi Hyperbole,

Thanks for your response, in fact that is pretty much what I already have and it works great at giving the illusion of 5 independent self contained sites. Now if I was going to use a conventional directory structure for any of those this would be ideal. But for one of the sites I wanted to use a php front controller.

The reason is this (my site is a multimedia gallery for many artists):

www.domain1.com/jonburger ---> should list all the work by jon burger (me)
www.domain1.com/jonburger/photography ---> should list all the photography work by jon burger only
www.domain1.com/photography ---> should list all the photography work from all the artists in the gallery
www.domain1.com/jonburger/rss ---> should return an rss feed of all work by jon burger
www.domain1.com/jonburger/photography/rss ---> should return feed of all the photography work by jon burger only
www.domain1.com/photography/rss ---> should return feed of all the photography work from all the artists in the gallery
www.domain1.com/rss ---> should return a feed of all current updates
www.domain1.com/illustration ---> should list all the illustration work by all the artists
etc.

Do you get the gist?

The idea of using the front controller (for domain1 site only, and in the domain1 directory) was to simplify the directory structure, make things easy to update and avoid duplication of data or files which would be needed if I actually had to create all the directories.

So I want all those links to point to one php file which will explode the url, fetch the corresponding data from the database and dispatch the page.

However there is also the directory www.domain1.com/images/anything... which shouldn't be sent to the front controller - the reason being is I don't want my front controller to be serving all the image requests too when apache is more efficient and capable.

The below works at sending all requests to the front controller, however it also sends www.domain1.com/images requests there too which means I have a hassle at displaying images easily - so I want to allow the $1 (regexp captured url string) for this directory, but not for any others.

code:
RewriteEngine on

RewriteCond %{HTTP_HOST} ^(ww+\.)?domain1\.com

RewriteCond %{REQUEST_URI} !/directory1/

RewriteRule ^(.*)$ /directory1/ [L] <--- no $1 meaning that all urls are refered to the front controller



SCRWD//MULTIMEDIA PORTAL

(Edited by smonkey on 10-02-2004 15:01)

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 10-03-2004 20:16

OK, I think I see what you re trying to do.

Try the following:

code:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain1\.com
RewriteCond %{REQUEST_URI} images/
RewriteCond %{REQUEST_URI} !/directory1/
RewriteRule ^(.*)$ /directory1/$1 [L]
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain1\.com
RewriteCond %{REQUEST_URI} !images/
RewriteCond %{REQUEST_URI} !/script.php/
RewriteRule ^(.*)$ /script.php/$1 [L]
RewriteCond %{HTTP_HOST} ^(ww+\.)?domain2\.com
.
.
.



-- not necessarily stoned... just beautiful.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-04-2004 00:13

Thanks Hyperbole, we have a winner.

By the way do you have a gmail account? if not do you want one? I have some invites to share

SCRWD//MULTIMEDIA PORTAL

hyperbole
Paranoid (IV) Inmate

From: Madison, Indiana, USA
Insane since: Aug 2000

posted posted 10-04-2004 22:09

smonkey: I'm glad to have been able to help. Thanks for offering me the gmail invite. I have a mail account on my server and am not really interested in gmail. Thanks for offering anyway.

-- not necessarily stoned... just beautiful.

smonkey
Paranoid (IV) Inmate

From: Northumberland, England
Insane since: Apr 2003

posted posted 10-04-2004 22:52

Jesus, once everyone wanted one, now you can't give them away! lol.

I'd rather give them out for good reason than to merely anyone, so no requests should there be maybe one person out there who hasn't already got a gmail account. Prize winning stories of despair or sexual deviance only

No doubt Tyberius already has one, but you can share your deviances with us too...

SCRWD//MULTIMEDIA PORTAL

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 10-05-2004 10:58

Have one, but don't use it. It is a very nice interface (complete with great and stupid parts...), but I've more than half a gig of mail archives - which I do not wish to fall into the hands of cooperations.

Now, if I could run GMail on my server...
Darn it that the semester starts again so soon... this could have been a nice summer project.

« BackwardsOnwards »

Show Forum Drop Down Menu