使用自定义 .htaccess 文件的虚拟主机上出现错误 404
P粉729198207
P粉729198207 2023-09-05 10:28:49
0
2
410
<p>我在本地 Linux 服务器上安装了 apache2。它有一个名为 <code>pcts.local</code> 的虚拟主机,其根目录为 <code>/var/www/repos/pcts/</code>。 pcts.local 的根目录内是一个 .htaccess 文件,如果未按如下方式给出,该文件会尝试重写 url 以包含 .php:</p> <pre class="brush:php;toolbar:false;">http://pcts.local/ -> http://pcts.local/index.php http://pcts.local/contact -> http://pcts.local/contact.php</pre> <p>问题是,<code>http://pcts.local/contact</code> 给出错误 404,但 <code>http://pcts.local/contact.php</code> 给出 200。</p> <h3>虚拟主机配置:</h3> <pre class="brush:php;toolbar:false;"><VirtualHost *:80> ServerName pcts.local ServerAdmin webmaster@localhost DocumentRoot /var/www/repos/pcts ErrorLog ${APACHE_LOG_DIR}/error.log CustomLog ${APACHE_LOG_DIR}/access.log combined </VirtualHost></pre> <h3>.htaccess 文件在 <code>/var/www/repos/pcts/</code></h3> <pre class="brush:php;toolbar:false;">RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}\.php -f RewriteRule ^(.+)$ $1.php [NC,L]</pre> <p>提前感谢您的帮助!</p>
P粉729198207
P粉729198207

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!