.htaccess 搞乱了 .php 扩展名?
好的,所以我有这个 mod_rewrite 规则,如果发送请求时未提供扩展名,它会在内部附加一个 .html 扩展名:
Options +FollowSymLinks RewriteEngine on # ## Internally rewrite extensionless file requests to .html files ## # # If the requested URI does not contain a period in the final path-part RewriteCond %{REQUEST_URI} !(\.[^./]+)$ # and if it does not exist as a directory RewriteCond %{REQUEST_FILENAME} !-d # and if it does not exist as a file RewriteCond %{REQUEST_FILENAME} !-f # then add .html to get the actual filename RewriteRule (.*) /$1.html [L] # # ## Externally redirect clients directly requesting .html page URIs to extensionless URIs # # If client request header contains html file extension RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP # externally redirect to extensionless URI RewriteRule ^(.+)\.html$ http://www.example.com/$1 [R=301,L]
我考虑过将此文件第一部分中的 .html 任何地方更改为 .php ,这样当有人请求.php 文件而不添加其扩展名,它仍然会转到该 .php 页面。事实证明,这行不通。为什么不呢?
Ok, so I have this mod_rewrite rule that internally attaches a .html extension if it is not provided when sending the request:
Options +FollowSymLinks RewriteEngine on # ## Internally rewrite extensionless file requests to .html files ## # # If the requested URI does not contain a period in the final path-part RewriteCond %{REQUEST_URI} !(\.[^./]+)$ # and if it does not exist as a directory RewriteCond %{REQUEST_FILENAME} !-d # and if it does not exist as a file RewriteCond %{REQUEST_FILENAME} !-f # then add .html to get the actual filename RewriteRule (.*) /$1.html [L] # # ## Externally redirect clients directly requesting .html page URIs to extensionless URIs # # If client request header contains html file extension RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^.]+\.)+html\ HTTP # externally redirect to extensionless URI RewriteRule ^(.+)\.html$ http://www.example.com/$1 [R=301,L]
I thought about changing anywhere it says .html to .php in the first part of this file so that when someone requests a .php file without adding it's extension, it would still go to that .php page. Turns out, this doesn't work. Why not?
My evidence here: http://appstorecrazy.com/OHNOEZ/NOTEST
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试以下处理 php 的规则:
Try following rules for handling php: