隐藏的index.php,同时使用QUERY_STRING从URL中的.php [英] Hide index.php AND .php from URLs while using QUERY_STRING

查看:87
本文介绍了隐藏的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.com/login~~V

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

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

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

我曾尝试使用位于解决方案<一href="http://stackoverflow.com/questions/3024631/htaccess-remove-php-extension-index-php-and-add-trailing-slash">here但它打破了example.com/login - 我想,因为我现在的使用功能/查询。有只小东西,我需要改变吗?

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?

推荐答案

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

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\.com
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_STRING从URL中的.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆