[英]Accessing URLS by www.example.com/page instead of www.example.com/page.php
What handles the disabling of the extension? 是什么处理了扩展的禁用? Is it APACHE or the PHP install?
是APACHE还是PHP安装? How would one go about configuring the web server where the .php extension is not required?
如何配置不需要.php扩展名的Web服务器? Is there an option that would make both www.example.com/page.php and www.example.com/page work as the URL?
是否有可以同时将www.example.com/page.php和www.example.com/page用作URL的选项?
通过Apache进行URL重写: http : //www.addedbytes.com/apache/url-rewriting-for-beginners/
Apache also has a setting called MultiViews
that will serve domain.com/index.*
as domain.com/index
, domain.com/example.*
as domain.com/example
, etc. 阿帕奇也有一个叫做设置
MultiViews
,将有助于domain.com/index.*
为domain.com/index
, domain.com/example.*
为domain.com/example
等。
I've occasionally run into issues where MultiViews
beats out mod_rewrite
rules, so I tend to turn it off. 我偶尔会遇到
MultiViews
击败mod_rewrite
规则的问题,因此我倾向于将其关闭。
Check out some articles from A List Apart on this topic: You use Apache (in your case) to setup ReWriteRule's and then you have PHP parse the url to fetch the correct information. 查看有关此主题的清单之外的一些文章:您使用Apache(以您的情况为例)设置ReWriteRule,然后让PHP解析URL以获取正确的信息。 (again, in your case. You can do this with many languages and http servers)
(同样,针对您的情况。您可以使用多种语言和http服务器执行此操作)
http://www.alistapart.com/articles/succeed/ http://www.alistapart.com/articles/succeed/
http://www.alistapart.com/articles/urls/ http://www.alistapart.com/articles/urls/
brianreavis is correct. brianreavis是正确的。 Here's an example for your .htaccess file:
这是您的.htaccess文件的示例:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
I just throw it all at PHP and parse it however I want in there: 我只是将其全部扔给PHP并对其进行解析,但是我想在其中进行:
.htaccess .htaccess
RewriteEngine On
RewriteRule !\.(js|ico|gif|jpg|png|css)$ @frontend.php
I use this in my .htaccess 我在.htaccess中使用它
<Files ~ "^[^.]+$">
ForceType application/x-httpd-php5
</Files>
That way I can remove all extensions (.php) from my files, and it will still work. 这样,我可以从文件中删除所有扩展名(.php),它仍然可以工作。
I use $_SERVER['PATH_INFO'] to retrieve the remainder of the path as parameters. 我使用$ _SERVER ['PATH_INFO']检索路径的其余部分作为参数。 Eg /page/param1/param2 where page is an actual php file.
例如/ page / param1 / param2,其中page是实际的php文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.