Apache没有重定向到Arch Linux

时间:2018-01-26 20:50:54

标签: php wordpress apache .htaccess archlinux

我正在尝试在我的localhost上配置一个Wordpress项目,但当我在localhost上打开浏览器时,我只看到我的wordpress项目根目录中的文件。

如果我点击index.php或访问localhost/index.php,它会按预期执行PHP。

我已安装apache 2.4php 7.2php-apache 7.2

我的项目位于/srv/http/mysite

/etc/httpd/conf/httpd.conf档案中的相关行:

LoadModule rewrite_module modules/mod_rewrite.so

# Virtual hosts
Include conf/extra/httpd-vhosts.conf
  

注意:由于httpd.conf非常大,我只展示了我认为相关的行。如果这还不够,我可以在pastebin上传整个文件。

文件/etc/httpd/conf/extra/httpd-vhosts.conf

<VirtualHost *:80>
    ServerAdmin webmaster@test.localhost
    DocumentRoot "/srv/http/mysite/"
    ServerName test.localhost
    ServerAlias test.localhost
    ErrorLog "/var/log/httpd/test.localhost-error_log"
    CustomLog "/var/log/httpd/test.localhost-access_log" common

    <Directory "/srv/http/mysite/">
        AllowOverride All
        Require all granted
    </Directory>
</VirtualHost>

文件/srv/http/mysite/.htaccess

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

我的/etc/hosts文件:

127.0.0.1   localhost
127.0.1.1   mycomputer_name
127.0.2.1   test.localhost
::1 localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

关于这最后一个文件,我注意到,如果我删除了<IfModule ...></IfModule>网站,它可以正常工作并重定向到index.php,但我不想更改此文件,因为它可以正常工作它位于使用ubuntu的远程服务器上。

主要问题是为什么这不起作用,但我也很高兴知道<IfModule mod_rewrite.c>正在做什么以及为什么它被忽略,即使LoadModule rewrite_module modules/mod_rewrite.so已启用。

我知道这不是一个简单的问题,但我没有在网上找到任何有同样问题的人。我将非常感谢任何帮助。

2 个答案:

答案 0 :(得分:3)

Apache需要设置为识别您的索引文件(在本例中为index.php)

您的目录中是否有以下内容

DirectoryIndex index.php

所以

<Directory "/srv/http/mysite/">
    DirectoryIndex index.php
    AllowOverride All
    Require all granted
</Directory>

答案 1 :(得分:0)

在httpd.conf中你应该有......

<IfModule dir_module> 
    DirectoryIndex index.php index.htm index.html
</IfModule>

这将是你的全部回落。

然后在你的httpd-vhosts.conf中,许多网站描述中的一个可能看起来像......

<VirtualHost *:8080>
    ServerAdmin admin@siteName.com
    DocumentRoot "e:/Stack/Sites/siteName/web"
    ServerName siteName
    ServerAlias siteNameUser
    <Directory "e:/Stack/Sites/SiteName/web">
        DirectoryIndex index.php
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
    </Directory>
    ErrorLog "logs/siteName.error.log"
    CustomLog "logs/siteName.access.log" common
</VirtualHost> 

注意:如果在httpd.conf中包含了回退默认值,则httpd-vhosts.conf站点声明中的DirectoryIndex index.php是不必要的

如果您不想使用默认端口80,则在任一文件中都会出现以下内容:Listen 8080

对于localhost,我使用:httpd.conf ... Listen 127.0.0.1:8080和httpd-vhosts.conf Listen 8080

在您的主机文件中,您需要定义类似... 127.0.0.1 siteName siteNameUser www.siteName.com

目前正在使用:Apache / 2.4.33(Win64)PHP / 7.2.4~MySql 5.7.22自制堆栈。 httpd-vhosts.conf示例部分适用于Drupal 8.x - 对于WP,您的DocumentRoot和目录会有所不同。

您可以侦听多个端口,例如8080用于开发,8081用于测试,8082用于测试。您还可以在httpd-vhosts.conf文件中包含许多不同的站点定义。

我更喜欢在httpd-vhosts.conf中定义所有网站,但您可以将它们放在httpd.conf中