【问题标题】:Invalid command 'location', perhaps misspelled or defined by a module not included in the server configuration无效的命令“位置”,可能拼写错误或由未包含在服务器配置中的模块定义
【发布时间】:2019-05-28 19:58:38
【问题描述】:

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

项目在带有 nginx 服务器的生产环境中运行。但是在本地开发,使用apache服务器。我已经在我的 ubuntu 机器上安装了 LAMP 堆栈。已经提供了一个虚拟主机文件,我已经设置了它。到目前为止,我已经在/etc/apache2/sites-available 下创建了xxx.conf 文件。

文件包括:

<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>


我还在/home/ubuntuser/Downloads/xxx-master/public 下创建了.htaccess 文件。从生产环境下载的这个文件的内容。

.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 有问题,但我不知道如何解决。

【问题讨论】:

    标签: php url-rewriting apache2


    【解决方案1】:

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

    参考apache2.4最新文档

    对我来说,您似乎想使用此重定向

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

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

    【讨论】:

      猜你喜欢
      • 2018-02-12
      • 2015-05-14
      • 2017-11-04
      • 2012-04-26
      • 2013-08-24
      • 2013-09-21
      • 2017-11-16
      • 2022-01-14
      相关资源
      最近更新 更多