[英]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/foo
到site.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.conf
, VirtualHost
配置或.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.