apache - mod rewrite absolute paths and links also to subfolder -
i want app portable root subdir without having change anything. want use alsolute paths, because in case app installed in root works out of box. root installation has priority one.
in order subfolder scenario working tried several things.
let app dynamicaly write .htaccess file based on folderstructure during initial install.to right rewritebase automaticaly set.this file looking that:
options +followsymlinks rewriteengine on rewritebase /subfolder/ rewritecond %{request_filename} !\.(css|js|ico|font|gif|jpg|png)$ [nc] rewriterule ^(.*)$ index.php [qsa,l]
of course no static file found in case, because absolute paths going root instead of subfolder.
then found out how let .htaccess find own rewritebase , tried following
options -indexes options +followsymlinks rewriteengine on ## determine rewritebase automatically/dynamically ## -- taken symfony .htaccess rewritecond %{request_uri}::$1 ^(/.+)/(.*)::\2$ rewriterule ^(.*) - [e=base:%1] # allow /images/*, /css/* & /js/* deny else, e.g. /lib/* # -- found in stackoverflow # original version is: #rewritecond %{request_uri} !^%{env:base}(public|images|css|js)/ [nc] #rewriterule . - [r=404,l] # ----- did not work ------ # -----canged rewritecond %{request_uri} !^%{env:base}(public|images|css|js)/ [nc] rewriterule ./index.php - [r=404,l] # rewrite other requests index.php if file rewritecond %{request_filename} !-f rewriterule ^(.*)$ index.php [qsa,l]
if hit landingpage static files loaded. click on menu 'home/' home prepended path of static files. so
http://www.local.dev/subfolder/home/public/bootstrap/css/bootstrap.min.css ---- not found
and if remove leading slashes static files. mean alter '/public' 'public'
dont know anymore
very appreciate help
due downvote ;) forgot dont want use <base>
tag either. want keep absolute paths in template. switch app whichever folder , have working ...... should possible somehow ..... works in symfony , drupal ...
update:
found solution: putting .htaccess file webroot folder, in case htdocs.
htdocs project anotherproject elseproject .htaccess
with simple rule
rewriteengine on rewritecond %{request_uri} !^/project/ rewriterule ^(.*)$ /project/$1
everything works - not quite satisfied since file kills other projects.
there other way achieve same ??
update
to prevent other projects rule add project folders rewritecond
rewriteengine on rewritecond %{request_uri} !^/project/ rewritecond %{request_uri} !^/otherproject/ rewriterule ^(.*)$ /project/$1
Comments
Post a Comment