简体   繁体   English

如何制作example.com/eat load example.com/eat.php?

[英]how to make example.com/eat load example.com/eat.php?

I know that it is trying to load the .html version, i am pretty sure at least. 我知道它正在尝试加载.html版本,至少我很确定。 I also think that it is something in an .htaccess file. 我也认为它是.htaccess文件中的内容。 I have tried a few different things from searching google and come up short. 我尝试了一些不同的东西,从搜索谷歌和短缺。 Basically i want it to work so that if there is no .html file by the name entered, it will go to the php one. 基本上我希望它工作,以便如果输入的名称没有.html文件,它将转到php。

Is this possible? 这可能吗?

Try this: 尝试这个:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -s
RewriteRule ^.*$ %{REQUEST_URI}.php [L,QSA]

The above rules say, if the requested file is of 0 size, or does not exist as a file, symbolic link, or directory and a file of the same name with a .php extension exists, then rewrite to the .php file. 上述规则说,如果请求的文件大小为0,或者不存在文件,符号链接或目录以及具有.php扩展名的同名.php ,则重写为.php文件。

This effectively rewrites site.com/foo to site.com/foo.php where foo can be anything. 这有效地重写site.com/foosite.com/foo.php其中foo可以是任何东西。

I'm not quite clear on what you want. 我不清楚你想要什么。 If you want to map non-existant .html files to a .php extension, try this instead: 如果要将不存在的.html文件映射到.php扩展名,请尝试以下操作:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-s
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.html$ $1.php [L,QSA]

This just says if the requested file does not exist and ends in .html , then grab the file name (less the .html ) and try to rewrite to the .php extension. 这只是说如果请求的文件不存在并以.html结尾,则获取文件名(减去.html )并尝试重写为.php扩展名。

In htaccess 在htaccess

RewriteEngine on 
RewriteRule ^eat$ eat.php [L]  

Use MultiViews 使用MultiViews

Add this to apache configuration (either in httpd.conf , VirtualHost config, or in .htaccess ): 将其添加到apache配置(在httpd.confVirtualHost配置或.htaccess ):

Options +MultiViews

Using rewriting for this is an overkill, when content-negotiation can do the job. content-negotiation可以完成工作时,使用重写是一种过度杀伤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用.htaccess将http://example.com/test.php设置为http://example.com/index.php?do=test? - How to make http://example.com/test.php to http://example.com/index.php?do=test using .htaccess? 如何让所有 example.com 页面重定向到 example.com/smth - How can I make all example.com pages redirect to example.com/smth 如何将example.com/index.php/lib更改为example.com/lib? - How to change example.com/index.php/lib to example.com/lib? 如何将example.com/index.php#anchor的URL重写为example.com/anchor? - How do I rewrite the URL for example.com/index.php#anchor to example.com/anchor? 如何将example.com/forum/index.php重定向到example.com/forum/ - How to redirect example.com/forum/index.php to example.com/forum/ Ubuntu-如何直接将example.com/opencart/index.php定向到http://example.com/和www.example.com? - Ubuntu - How direct example.com/opencart/index.php to http://example.com/ and www.example.com? example.com/wp-login.php将我重定向到example.com/example.com/wp-admin - example.com/wp-login.php redirects me to example.com/example.com/wp-admin 如何使用户系统为example.com/username - How to make users system example.com/username 如何在php中删除(.php /?ref = example.com)? - How to remove (.php/?ref=example.com) in php? example.herokuapp.com 重定向到 example.com - PHP - example.herokuapp.com redirection to example.com - PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM