问题描述
这是基本的HTML / PHP页面,没有查询字符串,等等。我已搜查高,低和寻找资源从URI去掉'的index.php,或删除名'.php等文件扩展名..甚至添加斜线。但是,每次我尝试使用它们,或者使用,我发现的例子,我得到一个500服务器错误。
This is for basic HTML/PHP pages, no query strings, etc.. I have searched high and low and find resources for removing the 'index.php' from the URI, or removing '.php' and other file extensions.. and even adding a trailing slash. But, everytime I try to use them all, or use examples that I have found, I get a 500 server error.
我可能会通过在一个页面上的查询字符串,但我真的只是想删除的index.php从索引页,并具有无文件扩展名的所有子页面。所以,这样的事情:
I may pass a query string on one page, but really I just want to remove 'index.php' from the index page and have all sub pages without the file extension. So, something like this:
domain.com/index.php到domain.com/~~Vdomain.com/page1.php~~V到domain.com/page1/~~Vdomain.com/page2.php~~V到domain.com/page2/~~Vdomain.com/page3.php到domain.com/page3~~V /
domain.com/index.php to domain.com/domain.com/page1.php to domain.com/page1/domain.com/page2.php to domain.com/page2/domain.com/page3.php to domain.com/page3/
所有的例子我能找到的都集中在的CMS等。与查询字符串,等等..没有仅仅关注基本URI上,我认为可能会是什么原因导致的错误我得到。
All the examples I can find are focused on CMSs, etc.. with query strings, etc.. nothing just focusing on the base URI, which I think might be what was causing the errors i was getting.
任何帮助是AP preciated!谢谢
Any help is appreciated !!Thanks
推荐答案
我得到这个从一个论坛一个相当有用的第一章一次 - 从来没有完全理解它,有一点需要注意;这意味着否斜线除非请求是一个目录。
I got this from a rather helpful chap on a forum once - never fully understood it, and there is one caveat; it implies no trailing slash unless the request is a directory.
不过,我认为这是值得帖子 - 一个大师在那里可以很容易地发现修复
However, I thought it was worth posting - a guru out there may easily spot the fix!?
# 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]
# remove index
RewriteRule (.*)index$ $1 [R=301]
# 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]
这篇关于htaccess的删除扩展名为.php,index.php文件,并添加斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!