PHP5 的 XAMPP 问题
我在我的网站上启用了 PHP5,并且我的虚拟主机需要我将以下内容添加到 .htaccess 文件中以使 PHP5 正常工作:
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
在本地,我正在运行 XAMPP 来开发代码,但 XAMPP 不想使用上面的 .htaccess 文件。
我认为这是 XAMPP 无法识别 php5 的问题(但如果我使用“application/x-httpd-php”而不是“application/x-httpd-php5”,它确实会识别 php)
我该如何解决这个问题? 我需要 .htaccess 文件看起来像上面这样,以便它们与我的网络主机一起使用,但我需要 XAMPP 在本地使用相同的文件而不进行更改!
I enabled PHP5 on my website and my webhost needs me to add the following to .htaccess files for PHP5 to work:
AddHandler application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
AddType application/x-httpd-php5 .php5 .php4 .php .php3 .php2 .phtml
Locally, I am running XAMPP to develop code, but XAMPP does not want to work with the .htaccess file above.
I think it is an issue with XAMPP not recognizing php5 (but it does recognize php if I use "application/x-httpd-php" instead of "application/x-httpd-php5")
How do I resolve this?! I need the .htaccess files to look like above so they work with my webhost, but I need XAMPP to work locally with the same files without making changes!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Apache 有
指令。 您可以使用它从您自己的服务器隐藏AddType
:并启动 apache
Apache has
<IfDefine>
directive. You can use it to hideAddType
from your own server:And start apache with
所以,你的处境有些艰难; 理想情况下,您的虚拟主机不需要您在 htaccess 文件中添加额外的内容。 由于不太了解 XAMPP,我无法提供具体的解决方案,但我可以给您一些指示:
您的网站主机正在运行使用 application/x-httpd-php5 的自定义编译版本的 PHP; 虽然完全可以自己构建 PHP 或找到已正确配置 SAPI 层的自定义构建,但您可能不想 这样做。
根据您的主机为 htaccess 文件提供的余地,可以使用或仅有条件地执行 PHP 模糊代码。 我没有测试过,您的虚拟主机可能已禁用此功能。 另外,您还必须找到一个适当的条件来进行测试。
我最喜欢的答案是忍住,并维护单独的 htaccess 文件。 我在我的网站上这样做; 我有一个 .htaccess.in 文件,其中包含“全局”声明,以及一个 htaccess.php 文件,该文件根据配置等生成真正的 .htaccess 文件。
希望有所帮助。
So, you're in kind of a tough place; ideally speaking your webhost should not need you to put extra gunk in your htaccess files. Not knowing XAMPP too well, I can't offer a specific solution, but I can give you some pointers:
Your webhost is running a custom compiled version of PHP that uses application/x-httpd-php5; while it is totally possible to build PHP yourself or find a custom build that has the SAPI layer configured appropriately, you probably don't want to do this.
Depending on how much leeway your host is giving htaccess files, it may be possible to use <IfDefine> or <IfModule> to only conditionally execute the PHP fudge code. I haven't tested, and your webhost may have disabled this functionality. Also, you will have to find an appropriate conditional to test against.
My favorite answer would be to suck it up, and maintain separate htaccess files. I do this on my website; I have a .htaccess.in file which contains "global" declarations, and an htaccess.php file which generates the real .htaccess file based on configuration, etc.
Hope that helps.
另一个简单的解决方案:更改配置文件名在家里。 例如在 httpd.conf 中:
现在您的家庭服务器将忽略您的“.htaccess”文件。 您将使用“.htaccess.home”文件对其进行配置。
Another simple solution: change the config file name at home. E.g. in httpd.conf:
Now your home server will ignore your ".htaccess" files. You'll configure it with ".htaccess.home" files.