隐藏的index.php,同时使用QUERY

编程入门 行业动态 更新时间:2024-10-22 17:22:59
本文介绍了隐藏的index.php,同时使用QUERY_STRING从URL中的.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我希望能够在使用QUERY_STRING从我的网址隐藏两者的index.php的.php。

I'd like to be able to hide both index.php and .php from my URLs while using QUERY_STRING.

现在,我成功地躲藏的index.php在我的.htaccess以下(访问某些目录时除外):

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]

我这样做,因为我有一定​​的功能,如登录/注销/登记,作为网页:example/login~~V

I'm doing this because I have certain functions, such as login/logout/registration, acting as pages: example/login

不过,我也有一些静态的页面不会被里面一个文件一堆PHP函数...如example/terms-and-conditions.php

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/terms-and-conditions.php

在被制服的精神,我怎么把那个URL到example/terms-and-conditions不破example/login?这甚至可能吗?我试着加入有关的index.php去除重写(显然去除index.php文件中的.php)无济于事.php为去除改写。

In the spirit of being uniform, how do I turn that URL into example/terms-and-conditions without breaking example/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.

我曾尝试使用位于解决方案here但它打破了example/login - 我想,因为我现在的使用功能/查询。有只小东西,我需要改变吗?

I did try using the solution located here but it broke example/login — I assume because the way I'm using functions/queries. Is there just something small I need to change there?

推荐答案

想通了!只是需要将二者结合起来,现在回想起来似乎是显而易见的。 :)

Figured it out! Just needed to combine the two, which seems obvious in retrospect. :)

RewriteEngine On # remove .php; use THE_REQUEST to prevent infinite loops RewriteCond %{HTTP_HOST} ^www\.domain\ RewriteCond %{THE_REQUEST} ^GET\ (.*)\.php\ HTTP RewriteRule (.*)\.php$ $1 [R=301] RewriteCond $1 !^(codex|_core|admin|index\.php) [NC] RewriteRule ^(.*)$ /index.php?/$1 [L] # remove slash if not directory RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} /$ RewriteRule (.*)/ $1 [R=301] # add .php to access file, but don't redirect RewriteCond %{REQUEST_FILENAME}.php -f RewriteCond %{REQUEST_URI} !/$ RewriteRule (.*) $1\.php [L]

更多推荐

隐藏的index.php,同时使用QUERY

本文发布于:2023-11-01 18:22:38,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550068.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:index   php   QUERY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!