1

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.

3
  • What is location of index.php and .htaccess? Are they in /subdir/ OR at root level? Commented Dec 18, 2013 at 7:25
  • they are in the subdir Commented Dec 18, 2013 at 7:51
  • ok provided an answer below. Commented Dec 18, 2013 at 8:37

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

3 Comments

well it worked sort of, now then i click on the links it still sends me to my root, but i can see the views .. i might help if you could look at the project.. you can download it at: github.com/ndavison/Nathan-MVC.. its under /classes/basemodel.php and under /views/maintemplate.php and ofc htacces in the root :)
I will try that once I get back to my computer. Meanwhile I have edited my answer, can you try it now?
epic it worked thanks alot :), I've really been struggling with this
0

Try this

RewriteEngine on

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.