问题
I have dynamic base URLs at /us/, /ca/ and /fr-ca/. Using the suggested RewriteCond as mentioned here, I was able to get this to work in most cases. The cases that it works are when index.php is not included in the URL, so:
- /us/path/subpath
- /us/path2/subpath
- /us/path/subpath
- /us/path2/subpath
For each of these $_SERVER['BASE'] will return /us/.
If my application plugs in index.php into the URL, BASE is no longer provided.
I've tried using RewriteCond $0#%{REQUEST_URI} ^((?:index.php/)?)([^#]*)#(.*)\1$, but the entire URL is returned as BASE
EDIT I see now, that with ^ I am telling htaccess to expect index.php before /directory/. Continuing to dig in here.
Edit 2:
My virtual host document root points to /var/www/html. Within /var/www/html is a real directory called us. Directories ca and fr-ca are symlinks to us.
My htaccess rewrite ls:
Options +FollowSymLinks
RewriteEngine on
RewriteCond $0#%{REQUEST_URI} ^([^#]*)#(.*)\1$
RewriteRule ^.*$ - [E=BASE:%2]
来源:https://stackoverflow.com/questions/46650151/dynamic-rewritebase-with-optional-index-php