使用 QUERY_STRING 时隐藏 URL 中的 index.php 和 .php
我希望能够在使用 QUERY_STRING 时从我的 URL 中隐藏 index.php 和 .php。
现在,我成功地隐藏了index.php(访问某些目录时除外),在我的.htaccess中使用以下内容:
RewriteEngine On
RewriteCond $1 !^(codex|_core|admin|index\.php) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
我这样做是因为我有某些功能,例如登录/注销/注册,充当页面:示例.com/login
但是,我也有一些静态页面,这些静态页面不会从包含一堆 PHP 函数的文件中受益...例如 example.com/terms-and-conditions.php
本着统一的精神,如何将该 URL 转换为 example.com/terms-and-conditions 而不破坏 example.com/login?这可能吗?我尝试添加关于index.php删除重写的.php删除重写(显然从index.php中删除.php)无济于事。
我确实尝试使用位于此处的解决方案但它破坏了 example.com/login - 我认为是因为我使用函数/查询的方式。我需要在那里改变一些小东西吗?
I'd like to be able to hide both index.php and .php from my URLs while using QUERY_STRING.
Right now, I'm successfully hiding index.php (except when accessing certain directories) with the following in my .htaccess:
RewriteEngine On
RewriteCond $1 !^(codex|_core|admin|index\.php) [NC]
RewriteRule ^(.*)$ /index.php?/$1 [L]
I'm doing this because I have certain functions, such as login/logout/registration, acting as pages: example.com/login
However, I also have some static pages that wouldn't benefit from being inside one file with a bunch of PHP functions... such as example.com/terms-and-conditions.php
In the spirit of being uniform, how do I turn that URL into example.com/terms-and-conditions without breaking example.com/login? Is this even possible? I've tried adding the .php removal rewrite about the index.php removal rewrite (obviously removing the .php from index.php) to no avail.
I did try using the solution located here but it broke example.com/login — I assume because the way I'm using functions/queries. Is there just something small I need to change there?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
想通了!只需要将两者结合起来,回想起来这似乎是显而易见的。 :)
Figured it out! Just needed to combine the two, which seems obvious in retrospect. :)