首页 > 解决方案 > 无效的命令“位置”,可能拼写错误或由未包含在服务器配置中的模块定义

问题描述

目前,我正在为一个项目设置本地环境。

项目在带有 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但我不知道如何解决它。

标签: phpurl-rewritingapache2

解决方案


您正在使用 apache 并在您的 .htaccess 中使用 Nginx 的约定。

参考apache2.4最新文档

对我来说,你似乎想重定向使用这个

RewriteRule ^/site(.*)$ https://local.xxx.com/$1或者也许这个

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]


推荐阅读