Cruelcrome
Cruelcrome

Reputation: 110

php path in mvc htaccess

Im trying to make a menu in a mvc structure.. The problem is that i have the site in a subdir, in my web root like:

localhost/subdir/

but when i click i link it goes back to my root. the menu is called in a model(static at the momment), in a associative array where the key is the link name, and the value is the path name, like so:

 $this->viewModel->set("mainMenu",array("Forside" => "/home", "Hjælp" => "/help"));

I when call it in a view file:

        foreach ($viewModel->get('mainMenu') as $key =>  $values){
              echo '<a href="'. $values. '">' . $key . '</a> ';
        }

My .htaccess file:

Options +FollowSymLinks
RewriteEngine on



RewriteRule ^([a-zA-Z]*)/?([a-zA-Z]*)?/?([a-zA-Z0-9]*)?/?$ index.php?controller=$1&action=$2&id=$3 [NC,L]

I have tried to make my links with a backslash, that dosen't work.. I have tried to make the links with no slash that works alsong as I am in localhost/subdir/home , but when i go to localhost/subdir/home/view, and click the home link it just goes to localhost/subdir/home/home

I've have tried defining a BASE_ROOT, dosen't work. And same with defining my DIRECTORY_SEPARATOR don't work :(

Sorry for my bad english, i really hope someone can help me here.

Upvotes: 1

Views: 184

Answers (2)

anubhava
anubhava

Reputation: 785146

Keep your links absolute i.e. starting with a slash as: /home, /help etc.

Add this rule in your /DocumentRoot/.htaccess:

Options +FollowSymLinks
RewriteEngine on

RewriteRule !^subdir /subdir/%{REQUEST_URI} [L,NC,R]

Remember this goes in parent directory of subdir

Upvotes: 2

Nisarg
Nisarg

Reputation: 3262

Try this

RewriteEngine on

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

Upvotes: 0

Related Questions