.HTACCESS can it be run from a subfolder? How?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

.HTACCESS can it be run from a subfolder? How?

Post by simonmlewis »

[text]DirectoryIndex index.html index.htm index.php
order allow,deny
allow from all

Options +FollowSymLinks
Options +Indexes
RewriteEngine On

RewriteRule ^([^/\.]+)/?$ index.php?page=$1&menu=home [L]
RewriteRule ^$ index.php?page=home&menu=home [L][/text]

Trying to run this from within : httpdocs/beta/

It won't work as it's looking in the ROOT.
So what do I need to add to make this work in /beta/, so I can test it for the client.

I cannot test it in a subdomain just yet.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: .HTACCESS can it be run from a subfolder? How?

Post by requinix »

You don't have to do anything special. Are you sure that .htaccess files are allowed and being interpreted?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .HTACCESS can it be run from a subfolder? How?

Post by simonmlewis »

Yes. But surely that HTACCESS script is looking from the ROOT? There is no mention of the 'beta' folder and I wouldn't know how to put that in globally in HTACCESS.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: .HTACCESS can it be run from a subfolder? How?

Post by requinix »

It's not "looking" anywhere. If you put it in the beta/ subfolder then it will apply to the beta/ folder and everything underneath. That's how these files work.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .HTACCESS can it be run from a subfolder? How?

Post by simonmlewis »

But do you then have to change the hyperlinks to /beta/contact, or can that be done in HTACCESS? As I have links that are /contact.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: .HTACCESS can it be run from a subfolder? How?

Post by requinix »

You'd have to change the links, but your .htaccess can't do that for you. The only thing it can do is rewrite (for example) /contact to /beta/contact but it will either (a) not let you use /beta URLs or (b) break your POSTed forms.

Typical solution is to define a site root somewhere like

Code: Select all

define("SITE_ROOT", "/beta");
and use that everywhere you construct a URL.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .HTACCESS can it be run from a subfolder? How?

Post by simonmlewis »

I need to point a particular URL to show a full URL.

RewriteRule ^products/ /index.php?page=products&menu=home [L]

This is clearly wrong, but I need /products.... go to to index.php?page=home&menu=home.

How do I do the first bit??

Simon
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: .HTACCESS can it be run from a subfolder? How?

Post by requinix »

Both of those try to rewrite from /products. Can't do that. The URLs have to be different.

Where is just "/products" supposed to go? For the other one, what URL is supposed to go to that?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .HTACCESS can it be run from a subfolder? How?

Post by simonmlewis »

This is the list so far.

RewriteRule ^portfolio/([^/]+) /index.php?page=applications&menu=$1 [L]
RewriteRule ^portfolio/([^/]+)/([^/]+)/([0-9]+) /index.php?page=applications&menu=$1&application=$1&appid=$2 [L]
RewriteRule ^appprods/([^/]+)/([^/]+) /index.php?page=appprods&menu=$1&app=$2 [L]
RewriteRule ^appprods/([^/]+)/([^/]+)/([0-9]+)/([0-9]+)/([^/]+) /index.php?page=products&menu=$1&application=$2&appid=$3&product=$4&h=$5 [L]

RewriteRule ^categ/([0-9]+)/([^/]+) /index.php?page=categ&catid=$1&category=$2&menu=categ [L]
RewriteRule ^categ/page/([0-9]+)/([^/]+)/([0-9]+) /index.php?page=categ&c=$1&cname=$2&menu=categ&pagenum=$3 [L]

RewriteRule ^product/([0-9]+)/([^/]+)/([0-9]+)/([^/]+) /index.php?page=product&catid=$1&category=$2&menu=categ&product=$3&h=$4 [L]

THIS is the one I am trying to sort out. Have tried just putting in any word after, that takes them to menu=categ.
RewriteRule ^products/([^/]+) /index.php?page=products&menu=categ [L]
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
RewriteRule ^$ index.php?page=home [L]
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .HTACCESS can it be run from a subfolder? How?

Post by simonmlewis »

Code: Select all

RewriteRule ^solutions/([^/]+) /index.php?page=solutions&menu=$1 [L]
RewriteRule ^solutions/sol/([^/]+) /index.php?page=$1&menu=sol [L]
This isn't working now.
The top one works. ..../solutions/sol, will take the user to index.php?page=solutions&menu=sol.
But ..../solutions/sol/sol_yachts just takes them back to the solutions/sol above.

Why is that?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply