本文介绍了Apache,如何处理标准URL等未知的php文件? – php程序员分享,有助于帮助完成毕业设计以及求职,是一篇很好的资料。
对技术面试,学习经验等有一些体会,在此分享。
我有一个Symfony网站,我在其中已重命名了主要的入口点,因此“ index.php”无法被搜索引擎访问或索引。它运作良好。但是,当我尝试访问此文件时,得到的404文件未找到,该404页由Apache处理,而不是由应用程序处理,这是标准的404页:
Not Found The requested URL was not found on this server.
我希望由Symfony应用程序处理/index.php(实际上为* .php)之类的URL,以显示具有良好布局的自定义错误页面。我的虚拟主机看起来像这样,我尝试添加“目录索引”指令,但没有成功。
# configuration/vhosts/prod/mywebsite.com-le-ssl.conf <IfModule mod_ssl.c> <VirtualHost *:443> ServerName www.mywebsite.com DocumentRoot /var/www-protected/mywebsite.com/public <Directory /var/www-protected/mywebsite.com/public> AllowOverride All Require all granted FallbackResource /my-secret-entry-point.php </Directory> RedirectMatch 404 /.git ErrorLog /var/log/apache2/mywebsite.com_error.log CustomLog /var/log/apache2/mywebsite.com_access.log combined RewriteEngine on RewriteCond %{SERVER_NAME} =mywebsite.com RewriteRule ^ https://www.%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent] SSLCertificateFile /etc/letsencrypt/live/www.mywebsite.com/fullchain.pem SSLCertificateKeyFile /etc/letsencrypt/live/www.mywebsite.com/privkey.pem Include /etc/letsencrypt/options-ssl-apache.conf </VirtualHost> </IfModule>
参考方案
这可以通过mod_rewrite
完成,并通过301
答复:
Options +FollowSymLinks DirectoryIndex index.php RewriteEngine On RewriteBase / RewriteCond %{THE_REQUEST} ^.*/index.php RewriteRule ^(.*)index.php$ /$1 [R=301,L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L]
默认错误文档可用于将错误代码分派到PHP:
ErrorDocument 404 https://mywebsite.com/error/page/404 ErrorDocument 500 https://mywebsite.com/error/page/500
然后,仍然可以发送任何想要的header()
-或仅显示具有相同标题的页面。
我已在数据库中使用datetime字段存储日期,使用PHP将“今天的日期”插入该字段的正确方法是什么?干杯, 参考方案 我认为您可以使用php date()函数
我正在尝试从服务器上的apache切换到nginx。唯一的问题是我在PHP脚本中使用的getallheaders()函数,该函数不适用于Nginx。我已经尝试过用户在getallheaders函数上的php站点上提供的注释,但这并不返回所有请求标头。请告诉我如何解决这个问题。我真的想切换到Nginx。 参考方案 您仍然可以使用它,但是您必须像这里一样重新定义…
我正在使用mysqli从数据库中获取某些数据。我正在使用的查询已设置为仅从数据库返回一行。有没有一种方法可以在不使用while循环的情况下获取该行的值?我知道一个while循环对于返回多于一行的行很有用,但是如果不需要while循环,我想避免这种情况,因为不必要的代码是不好的编程。 参考方案 是的-您可以使用:$row = $result->fetch…
举一个简单的例子,如果我想计算一个不使用磁盘存储的脚本的命中次数,我可以使用静态类成员来执行此操作吗?用户1:<?php $test = Example::singleton(); $test->visits++; ?> 用户2:<?php $test = Example::singleton(); $test->visits+…
如何更改默认网址。例如www.example.com/index.php-> www.example.com现在,我要将其设置为www.example.com/test.php。我应该在php.ini中进行更改吗? 参考方案 假设您正在使用apache,则可以通过DirectoryIndex指令执行此操作。Check out the docs。
最新评论