删除.php后缀的网址 [英] Remove .PHP File Extension in URL
问题描述
我有在URL中移除一个小问题,迫使PHP文件扩展名。
I am having a little issue forcing the .php file extension to be removed in the URL.
我成功地能够删除PHP文件扩展名,如果用户:
I am successfully able to remove .php file extension if user:
#Remove PHP if original request is /foo/bar.php
RewriteCond %{THE_REQUEST} "^[^ ]* .*?\.php[? ].*$"
RewriteRule ^(.*)\.php(\?.*)?$ $1$2 [R=301,L]
我的目标是把它也删除扩展,如果:
My goal is to get it also to remove the extension if:
# Remove PHP if original request is /foo.php/bar
我问,因为现在用户可以到网址并输入 HTTP:// WWW。 site.com/contact.php/about 它将使我有关页面。我的目标是强制删除的.php和渲染: http://www.site.com/contact/about
I ask because right now a user can go to the URL and type http://www.site.com/contact.php/about and it will render my about page. My goal is force the removal of the .php and render: http://www.site.com/contact/about
我希望拿code我上面并把它添加到,但我不能弄明白。
I was hoping to take the code I have above and add it to but I can not figure it out.
TIA
推荐答案
下面的的.htaccess 给我的请求参数,就可以得到页
the following .htaccess gives me the requested parameters, you can get "page"
AddDefaultCharset utf-8
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule .* - [L]
DirectoryIndex index.php
RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)/([^/]+)?$ index\.php?page=$1&s=$2&o=$3 [L]
RewriteRule ^([a-zA-Z0-9_-]{3,20})/([^/]+)?$ index\.php?page=$1&s=$2 [L]
RewriteRule ^([a-zA-Z0-9_-]{3,20})/?$ index\.php?page=$1 [L]
RewriteRule ^([a-zA-Z0-9_-]{3,20})?$ index\.php?page=$1 [L]
ErrorDocument 404 /404
获取页参数,然后调用它像这样
Get "page" parameter and then call it like this
include('inc/'.$_REQUEST['page'].'.php');
和记得从你的链接删除的.php
外部
and remember to remove .php
ext from your links
这篇关于删除.php后缀的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!