我使用 .htaccess 代码删除了所有网页的 .php 扩展名.这是我使用的代码:
I was using .htaccess code to remove .php extension for all my web pages. Here's the code I use:
RewriteEngine On
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-s]+)/$ /$1.php
它似乎不起作用.我想我错过了一些东西.当我输入 www.mysite.com/about/以获取 www.mysite.com/about.php 时,它返回错误 404(未找到页面).有人可以请说明一下.
It doesn't seem to work. I think I'm missing something. When I type www.mysite.com/about/ to get www.mysite.com/about.php it returns error 404 (page not found). Can someone please shed some light.
谢谢,保罗 G.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# If folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# and file exist
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# uncomment the below rule if you want the "/" to be required
# otherwise leave as is
# RewriteRule ^([^/]+)/$ $1.php [L]
# internally show the content of filename.php
RewriteRule ^([^/]+)/?$ $1.php [L]
以上规则将:
/ 之前的内容,如果存在作为文件名/ if one is present as the file name所以它适用于所有这些示例:
So it will work for all these examples:
http://domain.com/about/
http://domain.com/about
http://domain.com/contact/
http://domain.com/contact
如果你愿意,你可以删除 ?,就像注释规则一样,让它只接受以 / 结尾的 URL.
If you want you can remove the ?, like the commented rule, to make it accept only URL's that end with a /.
http://domain.com/about/
http://domain.com/contact/
现在这些是上述工作的重要步骤:
Now these are important step for the above to work:
.htaccess,例如 /home/youraccount/public_html/.htaccess-MultiViews.htaccess 位于同一位置,例如在您的情况下是 about.php 文件.htaccess on your root folder for example /home/youraccount/public_html/.htaccess-MultiViews.htaccess is for example in your case the about.php file这篇关于PHP/.htaccess:从 url 中删除 php 扩展名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
Zend 中的动作视图助手 - 解决方法?Action View Helper in Zend - Work around?(Zend 中的动作视图助手 - 解决方法?)
这是将 URI 与 PHP 中用于 MVC 的类/方法匹配的好方Is this a good way to match URI to class/method in PHP for MVC(这是将 URI 与 PHP 中用于 MVC 的类/方法匹配的好方法吗)
我在哪里保存 Zend Framework 中的部分(视图),以便Where do I save partial (views) in Zend Framework, to be accessible for all Views in my App?(我在哪里保存 Zend Framework 中的部分(视图),以
有一个网站的单一入口点.坏的?好的?没问题?Having a single entry point to a website. Bad? Good? Non-issue?(有一个网站的单一入口点.坏的?好的?没问题?)
MVC + 服务层在 Zend 或 PHP 中常见吗?Is MVC + Service Layer common in zend or PHP?(MVC + 服务层在 Zend 或 PHP 中常见吗?)
PHP MVC 方法中的 Hello World 示例Hello World example in MVC approach to PHP(PHP MVC 方法中的 Hello World 示例)