我在下面的htaccess规则几乎完美无缺。当我加载
http://localhost:8888/site/name/register/按预期重定向到http://localhost:8888/site/name/fr/register/。
但是当我加载http://localhost:8888/site/name/register(没有尾随斜杠)时,不会发生重定向。我确定我只需要在.htaccess规则中的某处添加一个斜杠但是找不到位置(将它添加到RewriteBase没有区别)。
RewriteEngine On
RewriteBase /site/name/
#some URI processing also occurs in routing.php!
RewriteCond $1 !^(fr|nl)$
#don't apply the rule to the assets folders
RewriteCond $1 !^css$
RewriteCond $1 !^js$
RewriteRule ^([^/]+)/.* /site/name/fr/$0 [L,R=301]
#Removes access to the system folder by users.
#Additionally this will allow you to create a System.php controller,
#previously this would not have been possible.
#'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
请注意,网站主页为http://localhost:8888/site/name
如何在http://localhost:8888/site/name/register处获得重定向?
答案 0 :(得分:1)
^([^ /] +)/。*表示第一个斜杠之前的所有内容。换句话说,需要斜杠。如果你只是删除斜杠它应该工作。
RewriteRule ^([^/]+).* /site/name/fr/$0 [L,R=301]