Apache 在htaccess中重写url
重写后.htaccess是否可以在url中隐藏子目录?我可以在我的URL中永久隐藏index.php,但我很难使用更长的索引。 这就是我想要达到的目标 所以网站应该接受/登录urlApache 在htaccess中重写url,apache,.htaccess,Apache,.htaccess,重写后.htaccess是否可以在url中隐藏子目录?我可以在我的URL中永久隐藏index.php,但我很难使用更长的索引。 这就是我想要达到的目标 所以网站应该接受/登录url https://example.com/login?param=abc¶mb=123,它应该在内部转到 https://example.com/core/auth/login?param=abc¶mb=123 但不在浏览器中显示这个奇怪的url。我希望core/auth/像index.php一样在地址
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
脚本上的路径信息将请求的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
?/core/auth/login
并不是您应该重写的URL,因为这仍然需要额外的重写才能处理(它不是最终的端点)。从您现有的指令来看,您似乎正在使用index.php
脚本上的路径信息将请求的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
。/core/auth/login
-这不是一个有效的端点,你是说/core/auth/login.php
还是什么?它是一个控制器函数。我使用MVC框架/core/auth/login
——这不是一个有效的终点,你是说/core/auth/login.php
还是什么?它是一个控制器函数。我使用MVC框架