我希望能够在使用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
发布评论