#1
  1. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Posts
    628
    Rep Power
    143

    Load from a subdirectory


    Hi all,

    I'm having trouble with a mod_rewrite case. I have the following .htaccess file in the main web directory:

    Code:
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteBase /myproject
      RewriteRule ^$ views/    [L]
      RewriteRule (.*) views/$1 [L]
    </IfModule>
    What I'm trying to do, is when a user requests a page of the form http://www.mysite.com/myproject/whatever, it loads http://www.mysite.com/myproject/views/whatever.

    But when I try the code presented above, I get a 404.

    So what am I doing incorrectly?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Posts
    628
    Rep Power
    143
    Any ideas on this one?
  4. #3
  5. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    This...

    RewriteRule ^$ views/

    isn't matching anything. ^ = start of value, $ = end of value. So your regular expression is matching "nothing" quite literally.

    Try something like this...
    Code:
    <IfModule mod_rewrite.c>
      RewriteEngine On
      RewriteCond %{REQUEST_URI} ^/myproject [NC]
      RewriteRule ^/myproject/(.*)$ /myproject/views/$1 [L]
    </IfModule>
    This is saying, if the request URI begins with /myproject, it should match the end portion of the URI and rewrite it.
    Last edited by Nilpo; January 24th, 2012 at 12:40 PM.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Apr 2005
    Posts
    628
    Rep Power
    143
    Thanks for the tip Nilpo. I just confirmed with the Unix team that our webservers are configured to ignore .htaccess files. That's why my really simple examples I was trying didn't work either. Occum's razor and all.
  8. #5
  9. Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    New Springfield, OH
    Posts
    1,236
    Rep Power
    1469
    Originally Posted by lokisapocalypse
    Thanks for the tip Nilpo. I just confirmed with the Unix team that our webservers are configured to ignore .htaccess files.
    Well I guess that would certainly explain it too.
    Don't like me? Click it.

    Scripting problems? Windows questions? Ask the Windows Guru!

    Stay up to date with all of my latest content. Follow me on Twitter!

    Help us help you! Post your exact error message with these easy tips!

IMN logo majestic logo threadwatch logo seochat tools logo