Dynamic RewriteBase with optional index.php

懵懂的女人 提交于 2019-12-23 23:51:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!