BagoZonde Posted March 22, 2013 Share Posted March 22, 2013 Hello, For testing purposes I need to run site from /test_directory/, however every element in index.php and other places uses absolute path, e.g.: /styles/style.css /images/some_image.jpg I was trying rewriting base to /test_directory/ but unfortunately instead of reading from: www.mysite.com/test_directory/styles/style.css PHP is reading from: www.mysite.com/styles/style.css where that file of course not exists. I'm not familiar with RewriteBase, however I think it should work that way if I want change base dir to subdirectory. So I need to change absolute path to every single file and every link. Here we go with my .htaccess: RewriteEngine On RewriteBase /test_directory/ RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.+)$ index.php?var=$1 [QSA,L] Any help will be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/276008-rewritebase-to-subdirectory-as-absolute-path-even-for-leading-slash/ Share on other sites More sharing options...
BagoZonde Posted June 18, 2015 Author Share Posted June 18, 2015 (edited) Ok, one person asked me about this problem privately an hour ago, so after a few years, well, just two years, I can answer to my question . Hope it helps other. This is very easy task, as .htaccess must be available in both directories. And the only difference between them is RewriteBase parameter: For main directory it will be: RewriteBase / And for test_directory it will be just: RewriteBase /test_directory So it's easy to keep whole project in separate directory nested in other one. I must say that it's funny how everything has changed in my development workflow since this post. For now I'm using VM with Vagrant and Ansible provisioning, Jenkins and so on. For this particular example I would rather expose my VM for somebody, or just create some staging server, etc. however sometimes it's quicker just to put some files somewhere so here is an answer. I hope everything's clear . Edited June 18, 2015 by BagoZonde Quote Link to comment https://forums.phpfreaks.com/topic/276008-rewritebase-to-subdirectory-as-absolute-path-even-for-leading-slash/#findComment-1514281 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.