.htaccess是否有可能在重写后在url中隐藏子目录?我能够将URL中的index.php永久隐藏,但是我很难与更长的URL在一起。这就是我要实现的目标。
因此,网站应接受/ login url https://example.com/login?param=abc¶mb=123
,并且应在内部访问https://example.com/core/auth/login?param=abc¶mb=123
但不要在浏览器中显示此外观怪异的url。我想要core/auth/
像index.php那样永久不可见的地址栏。
#RewriteRule ^(.*)$ /core/auth/login [R,L]
下面是我的代码。
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
#my code here...
#RewriteCond %{REQUEST_URI} /login
#RewriteRule ^(.*)$ /core/auth/login [R,L]
/core/auth/login
并不是您应该重写的URL,因为它仍然需要进行其他重写才能处理(这不是最终的终点)。从您现有的指令看来,您正在index.php
脚本上使用path-info将请求的URL路径传递到框架。例如。index.php/core/auth/login
。因此,请尝试以下类似的方法:
RewriteEngine On
# Handle requests to "/login"
RewriteRule ^login$ index.php/core/auth/login [L]
# Framework
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
尽管我认为最好在框架中创建一条附加路由,而不是.htaccess
为此使用路由?
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句