简体   繁体   English

通过www.example.com/page而不是www.example.com/page.php访问URL

[英]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 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/indexdomain.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.

相关问题 如何创建网址,例如www.example.com/EN/login - How to create URLs like www.example.com/EN/login Avoid multiple page redirects http://example.com &gt; https://example.com -&gt; https://www.example.com - Avoid multiple page redirects http://example.com > https://example.com -> https://www.example.com URL重写从www.example.com/blog/blog.php到www.example.com/blog/ - URL rewriting going from www.example.com/blog/blog.php to just www.example.com/blog/ 为什么“www.example.com”与“example.com”不一样? - Why is “www.example.com” not the same as “example.com”? PHP $ _GET www.example.com/folder/file?id=2类型网址存在问题 - PHP $_GET problems with www.example.com/folder/file?id=2 type URLs example.com和www.example.com被视为不同的会话 - example.com and www.example.com are treated as different sessions 使用htaccess将http://www.example.com/重定向到https://www.example.com/ - redirect http://www.example.com/ to https://www.example.com/ with htaccess 在example.com中使用setcookie(),在www.example.com中找不到cookie - setcookie() in example.com, cookie not found in www.example.com 出现www.example.com的根目录,但www.example.com/dev/admin给出了错误 - www.example.com at the root shows up but www.example.com/dev/admin gives error 仅匹配“ www.example.com”,而不匹配“ www。 一些文字” - Match only “www.example.com” but not “www. some text”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM