php - 无效的命令“位置”,可能拼写错误或由未包含在服务器配置中的模块定义
问题描述
目前,我正在为一个项目设置本地环境。
项目在带有 nginx 服务器的生产环境中运行。但是在本地开发,使用apache服务器。我已经在我的 ubuntu 机器上安装了 LAMP 堆栈。已经提供了一个虚拟主机文件,我已经设置了它。到目前为止,我已经xxx.conf
在/etc/apache2/sites-available
.
该文件包括:
<VirtualHost *:80>
ServerName xxx
DocumentRoot /home/ubuntuser/Downloads/xxx-master/public
<Directory "/home/ubuntuser/Downloads/xxx-master/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride all
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/xxx-error.log
CustomLog ${APACHE_LOG_DIR}/xxx-access.log combined
SetEnv ENVIRONMENT "development"
</VirtualHost>
我还在 .htaccess 下创建了 .htaccess 文件/home/ubuntuser/Downloads/xxx-master/public
。从生产环境下载的这个文件的内容。
文件内容.htaccess
为:
RewriteEngine On
RewriteBase /
location ~ ^/site { rewrite ^/site(.*)$ https://local.xxx.com/$1 redirect;}
所以,当我local.xxx.com
在浏览器中输入时,它会给出 500 内部错误。
所以,我是xxx-error.log
在虚拟主机配置文件中定义的。我已经打开了。内容是:
[Tue May 28 22:23:33.231851 2019] [core:alert] [pid 5677] [client 127.0.0.1:56504] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: RewriteBase takes one argument, the base URL of the per-directory context
[Tue May 28 22:23:33.254608 2019] [core:alert] [pid 5678] [client 127.0.0.1:56506] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: RewriteBase takes one argument, the base URL of the per-directory context, referer: http://local.xxx.com/
[Tue May 28 22:33:22.300863 2019] [core:alert] [pid 6326] [client 127.0.0.1:56740] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: Invalid command 'location', perhaps misspelled or defined by a module not included in the server configuration
[Tue May 28 22:33:22.317420 2019] [core:alert] [pid 6327] [client 127.0.0.1:56742] /home/ubuntuser/Downloads/xxx-master/public/.htaccess: Invalid command 'location', perhaps misspelled or defined by a module not included in the server configuration, referer: http://local.xxx.com/
所以,我知道有问题,.htaccess
但我不知道如何解决它。
解决方案
您正在使用 apache 并在您的 .htaccess 中使用 Nginx 的约定。
参考apache2.4最新文档
对我来说,你似乎想重定向使用这个
RewriteRule ^/site(.*)$ https://local.xxx.com/$1
或者也许这个
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
推荐阅读
- asp.net-core - 共享资源本地化不起作用
- database - 在不更新 Oracle 中的列值的情况下,有没有办法将数据存储在变量中并使用 where 条件对这些数据进行计数?
- visualization - grafana仪表中的数据覆盖
- firebase - Firebase Analytics - 事件报告 - 深入了解事件参数
- javascript - 为什么我的 Vue.js Nuxt 应用程序中未定义我的图像请求
- leaflet - React-Leaflet 瓷砖有不同的对比度?
- c# - 从 DocuSign API 请求访问令牌时收到 400 错误请求消息
- java - 验证输入数据类型
- python - 将字符串拉伸到字符数 [Python]
- ms-access - 是否可以通过远程桌面服务使用 MS-Access 应用程序?