[英]Without using the parameters in URL, what are the ways to access other pages in php
[英]How to get to php pages without using .php in URL
我有一个 static 网站,其中包含 index.php、blog.php、contact.ZE1BFD762321E409CEE4 等文件
如何让我的网站地址正常工作,以便 www.site.com/blog 将您带到 blog.php?
我认为 htaccess 可以为我做到这一点,但我是一个 php 菜鸟!
我目前使用的唯一替代方法是创建名为“博客、联系人等”的单个文件夹,其中包含另一个 index.php 文件
谢谢
是的,您可以使用 mod_rewrite 重写所有 url。 以下将所有不存在的文件和文件夹重写为请求的文件名.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php [L]
访问/blog
并且它不是现有目录将导致此规则将其重写为/blog.php
。
像这样的事情应该这样做。
RewriteEngine on
RewriteRule ^(.*)$ $1.php [NC]
阅读 mod_rewrite: http://httpd.apache.org/docs/1.3/mod/mod_rewrite.html
在服务器上的 .htaccess 文件中添加
Options +MultiViews
我有一个 static 网站,其中包含 index.php、blog.php、contact.ZE1BFD762321E409CEE4 等文件
如果您使用 PHP 生成文档,则该站点是动态的,而不是 static。
如何让我的网站地址正常工作,以便 www.site.com/blog 将您带到 blog.php?
假设您使用的是 Apache,请打开MultiViews
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.