Remove in between folder structure from the url in a php website

Posted by pabz on Stack Overflow See other posts from Stack Overflow or by pabz
Published on 2012-10-01T15:40:17Z Indexed on 2012/10/02 3:37 UTC
Read the original article Hit count: 140

I have a php website having following folder structure (basic structure).

  • project_name
    • app
      • controller
      • model
      • view
    • css
    • js
    • img
    • index.php

So when I view index.php in WAMP the url is http://localhost/project_name/

But when I go inside the site (eg. login.php which resides under view folder) url is like this. http://localhost/project_name/app/view/login.php

I found that using .htaccess we can change the urls. So I tried this (in .htaccess).

RewriteEngine on
RewriteBase /
Redirect 301 /project_name/app/view/login.php /project_name/login.php
RewriteRule ^/project_name/login.php$ /project_name/app/view/login.php [L]

Now url is http://localhost/project_name/login.php It is correct. But it seems php does not use the original link to grab the file (ie. from /project_name/app/view/login.php) but from here /project_name/login.php

So it throws 404 error.

What should I change? Please help me, i am just trying to hide /app/view/ part from the url so that user won't see my folder structure. I have read about various ways of doing that for about 9hrs today but still couldn't get anything working correctly.

Hope my question is clear enough. Any help is greatly appreciated!

© Stack Overflow or respective owner

Related posts about php

Related posts about .htaccess