Reputation: 183
I'm trying the following.
I have this directory structure, which is available in our network at IP address xxx.xxx.xxx.xxx
root
-dir1
-dir2
-dir3
Now in my dir1-folder, I have a site that uses the following .htaccess file
RewriteEngine On
RewriteBase /dir1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA]
On my site, I am linking the sources and pages with a preceding "/", like "/details" or "/css/app.css"
The problem is, that the links always go to the root folder because of the preceding "/".
What can I do to make the links "stay" in the subdirectory without having to edit all links and sources?
I have tried to use
RewriteBase /
RewriteBase /dir1
RewriteBase /dir1/
RewriteBase dir1
Any help is greatly appreciated. Thanks!
Upvotes: 2
Views: 6906
Reputation: 74018
RewriteBase
doesn't change anything, because it applies only to relative path targets.
The RewriteBase directive specifies the URL prefix to be used for per-directory (htaccess) RewriteRule directives that substitute a relative path.
Because your target is already the absolute /index.php
, you can omit RewriteBase
altogether.
From the given .htaccess, it seems index.php returns the requested files. So in this case, I would just prefix the path with the appropriate directory, e.g.
RewriteRule ^(.*)$ /index.php?path=/dir1/$1 [NC,L,QSA]
or maybe give an additional argument, if this works better with the script, like
RewriteRule ^(.*)$ /index.php?path=$1&subdir=dir1 [NC,L,QSA]
Upvotes: 4