.htaccess with front/back ends

Heya,

This is probably an easy problem thats got me boggled at the moment.
Goal: I am trying to separate a front-end and a back-end.

I have these directories
system/application/controllers/frontend
system/application/controllers/backend

I would like it so this would load the frontend parts:
http://workspace/index.php
http://workspace/test.php

and this would load the backend parts:
http://workspace/backend/index.php
http://workspace/backend/test.php

My current .htaccess file:
RewriteEngine On
RewriteRule ^([-a-zA-Z._]+)$ system/application/controllers/$1 [L]

As you can see it currently routes to a controller:
So loading: http://workspace/test.php
Actually Loads: http://worspace/system/application/controllers/test.php

I have searched google but couldn’t find anything with handling something like this.

Thanks for any Advice :slight_smile:

This isn’t clear for me.

Are those first four URLs the URLs you want to access in a browser? Or are they the URLs you want to map requests to?

If the former, how do those map to a controller?

If the latter, how do you differentiate a URL that should point to a frontend controller from one that should point to a backend controller?

Hey, JR!

On top of Dan’s questions:

  1. Have you setup workspace (OR frontend) as a VirtualHost? If so, change its DocumentRoot to system/application/controllers/frontend so that’s what you get with http://workspace. Then duplicate that VH for backend but use system/application/controllers/backend as its DocumentRoot.

As Dan asked, how do you expect to differentiate the redirection to index.php from test.php? You’ve given us NOTHING! DITTO for the backend!

Okay, as I’ve repeated many times, before you start coding a mod_rewrite redirection, write a specification for yourself so you actually KNOW what gets redirected where. When the specifications “cross,” you know you’ll have a problem unless you use exclusions (generally RewriteCond statements in your mod_rewrite block).

Let’s examine your mod_rewrite code while we’re at it:

RewriteEngine On
# Okay so far
RewriteRule ^([-a-zA-Z._]+)$ system/application/controllers/$1 [L]
# WHAT?  Redirect EVERY request made to SOME
# (where is your DocumentRoot?)
# DocumentRoot file to
# system/application/controllers/test.php. 
# Is that what you really want to do?

Finally, you’ve been in here before - you don’t remember to look at the mod_rewrite tutorial linked in my signature? :headbang:

Regards,

DK

Hey thanks for the fast reply, I havent slept actually lol.

Yes Id like to map all these URL to the browser.
I am trying to have a private administator area and a public site.
Its to separate a login area (like a CMS type of thing)

So if one went to
http://workspace/test.php
loads: system/application/controllers/test.php controller

http://workspace/backend/test.php
loads: system/application/controllers/backend/test.php controller

I suppose itd be easier to just call it admin instead of backend :stuck_out_tongue:

That actually is making sense to me the more I think about it.

Okay my thought was this:
I have folders for:
/frontend/index.php
/backend/index.php

I thought there is like a way to make Apache read the URL directory
%{ONE_OF_THESE}

And then you do something like (the ${ONE_OF_THESE} would be either frontend or backend

RewriteRule ^([-a-zA-Z.]+)$ system/application/controllers/[B]{THE%_THING}[/B]/$1 [L]

Hey sorry I have a document root set at index.php sorry i didnt paste it :stuck_out_tongue:

Well I couldnt figure out a tutorial anywhere on this because I thought what I was looking for is some type of %{DIRECTORY_FETCH} then place is into the rewrite rule and I couldnt think what to look at lol

Man the above is confusing to read, sorry Im not good at that… But man you guys must have this sitepoint plugged into your cell phones I posted this in the middle of the night i didnt expect a reply so fast LOL

I gotta read your site better you gotta make your signature in bold DKLyn :stuck_out_tongue:

Still not very clear. Maybe this is what you mean?

RewriteRule ^/?backend/([-a-zA-Z._]+)$ system/application/controllers/backend/$1 [L]
RewriteRule ^([-a-zA-Z._]+)$ system/application/controllers/frontend/$1 [L]

Yeah that is what i ment. Ill try this out :stuck_out_tongue:

Congrats on your project man thats amazing, sweet mercy LOL I had no idea you were a high roller :smiley:

Thanks, it’s the first time I’ve ever sold a site anywhere near that price :slight_smile: